Login dmv de Auth Pear Class...
ik heb de PEAR classes Auth en DB geinstalleerd en heb nu deze login-pagina:
(de functies zijn dus bestaande (niet door mij gemaakte) functies)
hij geeft een foutmelding wanneer ik inlog en ik weet niet waarom...
"Je voert een fout password en/of usernaam in! "
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/*
use as an include in <body> to make the form appear on a single line.
Before using, set up the dsn line below with your database info:
"dsn" => "mysql://username:password@localhost/database" ,
this example uses a table call people with the format:
CREATE TABLE `people` (
`personid` mediumint(4) NOT NULL auto_increment,
`personname` char(32) NOT NULL default '',
`email` char(100) NOT NULL default '',
`passw` char(32) NOT NULL default '',
`persontype` char(12) default 'Any'
PRIMARY KEY (`personid`),
KEY `email` (`email`)
) TYPE=MyISAM
*/
include('includes/mysql.inc.php');
require_once('PEAR.php');
require_once('DB/DB.php');
require_once('Auth/Auth.php');
//---- setup Auth class
$params = array(
"dsn" => "mysql://username:password@localhost/database" ,
"table" => "people" ,
"usernamecol" => "email" ,
"passwordcol" => "passw",
"db_fields" => array('personid','username','persontype')
);
$a = new Auth ("DB" ,$params, 'myLogin' );
//---- REGISTER
if ($_POST['register']) {
// already filled in details, so save now
if ($_POST['username']) {
$err=$a->addUser($_POST['username'],$_POST['password'],
array('username'=>$_POST['username'],'persontype'=>'Contributor'));
if ($err==1) {
$a -> start ();
$contrib=&$_SESSION['auth']['data'];
} else {
// your error handling here ($err contains PEAR error)
print_r($err);
die();
}
} else {
myRegister();
}
//---- LOGIN
} else {
// normal login
$a->setLoginCallback('myLoginCallback');
$a -> start ();
if ( $a -> getAuth ()) {
// point to session data for convenience
$contrib=&$_SESSION['auth']['data'];
//---- LOGOUT
if( $_GET ['act'] == "logout" ) {
$contrib=NULL;
$a->setLogoutCallback('myLogoutCallback');
$a -> logout ();
$a -> start ();
}
} else {
//failed to login
echo '<font color="#990000">Je voert een fout password en/of usernaam in!</font>';
} // $a->getAuth()
} // $_GET['register']
// logged in or registered okay
if (!empty($contrib)) {
echo 'Currently logged in as: '.$contrib['personname'];
echo ' <input type="submit" name="logout" id="logout" value="Logout" onClick="document.location.href=\''.basename($_SERVER["PHP_SELF"]).'?act=logout\'">';
}
//print_r($_SESSION);
//print_r($a);
function myLogin() {
// note that even if you have different names for the username and password fields
// in your database, you must use "username" and "password" in the form.
// no validation included
echo '<p class="login">';
echo '<form name="login" method="post" action="'. $_SERVER['PHP_SELF'] . '">';
echo 'Username:<input type="text" name="username" value="'.$_POST['username'].'">';
echo 'Password <input type="password" name="password" size="10">';
echo '<input type="submit" name="login" id="login" value="Login">';
// echo '<input type="submit" name="sendpw" id="sendpw" value="Forgotten Password?">';
echo '<input type="submit" name="register" id="register" value="Register...">';
echo '</form></p>';
} //myLogin
function myRegister() {
// note that even if you have different names for the username and password fields
// in your database, you must use "username" and "password" in the form.
// validation required
echo '<p class="login">';
echo '<form name="register" method="post" action="'. $_SERVER['PHP_SELF'] . '">';
echo 'Full Name:<input type="text" name="personname" value="'.$_POST['personname'].'">';
echo 'Username:<input type="text" name="username" value="'.$_POST['username'].'">';
echo 'E-mail:<input type="text" name="email" value="'.$_POST['email'].'">';
echo 'Password <input type="password" name="password" size="10">';
echo '<input type="submit" name="register" id="register" value="Register Now">';
echo '</form></p>';
} //myRegister
function myLoginCallback() {
// this is called when the user initially logs in using the form
} // myLoginCallBack
function myLogoutCallback() {
// this is called when logout is called, object $a is no longer available
} // myLogoutCallBack
?>
/*
use as an include in <body> to make the form appear on a single line.
Before using, set up the dsn line below with your database info:
"dsn" => "mysql://username:password@localhost/database" ,
this example uses a table call people with the format:
CREATE TABLE `people` (
`personid` mediumint(4) NOT NULL auto_increment,
`personname` char(32) NOT NULL default '',
`email` char(100) NOT NULL default '',
`passw` char(32) NOT NULL default '',
`persontype` char(12) default 'Any'
PRIMARY KEY (`personid`),
KEY `email` (`email`)
) TYPE=MyISAM
*/
include('includes/mysql.inc.php');
require_once('PEAR.php');
require_once('DB/DB.php');
require_once('Auth/Auth.php');
//---- setup Auth class
$params = array(
"dsn" => "mysql://username:password@localhost/database" ,
"table" => "people" ,
"usernamecol" => "email" ,
"passwordcol" => "passw",
"db_fields" => array('personid','username','persontype')
);
$a = new Auth ("DB" ,$params, 'myLogin' );
//---- REGISTER
if ($_POST['register']) {
// already filled in details, so save now
if ($_POST['username']) {
$err=$a->addUser($_POST['username'],$_POST['password'],
array('username'=>$_POST['username'],'persontype'=>'Contributor'));
if ($err==1) {
$a -> start ();
$contrib=&$_SESSION['auth']['data'];
} else {
// your error handling here ($err contains PEAR error)
print_r($err);
die();
}
} else {
myRegister();
}
//---- LOGIN
} else {
// normal login
$a->setLoginCallback('myLoginCallback');
$a -> start ();
if ( $a -> getAuth ()) {
// point to session data for convenience
$contrib=&$_SESSION['auth']['data'];
//---- LOGOUT
if( $_GET ['act'] == "logout" ) {
$contrib=NULL;
$a->setLogoutCallback('myLogoutCallback');
$a -> logout ();
$a -> start ();
}
} else {
//failed to login
echo '<font color="#990000">Je voert een fout password en/of usernaam in!</font>';
} // $a->getAuth()
} // $_GET['register']
// logged in or registered okay
if (!empty($contrib)) {
echo 'Currently logged in as: '.$contrib['personname'];
echo ' <input type="submit" name="logout" id="logout" value="Logout" onClick="document.location.href=\''.basename($_SERVER["PHP_SELF"]).'?act=logout\'">';
}
//print_r($_SESSION);
//print_r($a);
function myLogin() {
// note that even if you have different names for the username and password fields
// in your database, you must use "username" and "password" in the form.
// no validation included
echo '<p class="login">';
echo '<form name="login" method="post" action="'. $_SERVER['PHP_SELF'] . '">';
echo 'Username:<input type="text" name="username" value="'.$_POST['username'].'">';
echo 'Password <input type="password" name="password" size="10">';
echo '<input type="submit" name="login" id="login" value="Login">';
// echo '<input type="submit" name="sendpw" id="sendpw" value="Forgotten Password?">';
echo '<input type="submit" name="register" id="register" value="Register...">';
echo '</form></p>';
} //myLogin
function myRegister() {
// note that even if you have different names for the username and password fields
// in your database, you must use "username" and "password" in the form.
// validation required
echo '<p class="login">';
echo '<form name="register" method="post" action="'. $_SERVER['PHP_SELF'] . '">';
echo 'Full Name:<input type="text" name="personname" value="'.$_POST['personname'].'">';
echo 'Username:<input type="text" name="username" value="'.$_POST['username'].'">';
echo 'E-mail:<input type="text" name="email" value="'.$_POST['email'].'">';
echo 'Password <input type="password" name="password" size="10">';
echo '<input type="submit" name="register" id="register" value="Register Now">';
echo '</form></p>';
} //myRegister
function myLoginCallback() {
// this is called when the user initially logs in using the form
} // myLoginCallBack
function myLogoutCallback() {
// this is called when logout is called, object $a is no longer available
} // myLogoutCallBack
?>
Er zijn nog geen reacties op dit bericht.