na activatie verkeerde wachtwoord/gebruikernaam?
als ik me registreer krijg ik via de email een 8 cijferige code opgestuurd als ik me dan inlog dan moet ik op een link klikken om me te activeren, als ik dan me gebruikersnaam en wachtwoord en activatie code heb ingevoerd en de sessies verwijder om opnieuw in te loggen zegt hij dat ik een verkeerde wachtwoord of gebruikersnaam heb ingevoerd maar er is niks veranderd tijdens de activatie behalve dat er bij activated een 1 komt te staan om te verificeren dat ik me geactiveerd heb hoe komt dit?
login.php:
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
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
<head>
<link rel="stylesheet" type="text/css" href="css/king.css">
</head>
<br>
<?php
include('config.php');
include('function.php');
if(isset($_POST['submit'])){
$result = user_login($_POST['username'], $_POST['password']);
if ($result != 'Correct') {
echo 'Wrong username/password';
session_unset ();
session_destroy ();
$checkuser = "SELECT activated FROM users WHERE username='$_POST[username]'";
$query = mysql_query($checkuser);
} elseif($query == 0){
echo 'You need to activate before you can play click <a href=?pagina=activate.php> here </a> to activate<br>';
} elseif ($result == 'Correct') {
header("Location: index.php");
}
}
session_start();
if (!SESSION_IS_REGISTERED('id')&&!SESSION_IS_REGISTERED('username')){
php?>
<center>Login</center>
<br>
<br>
<form action="?pagina=login.php" method="post">
<b>Username:</b> <input type="text" size="16" maxlength="20" name="username"><br>
<b>Password:</b> <input type="password" size="16" maxlength="30" name="password" ><br>
<input type="submit" name="submit" value="Login">
</form>
<?php
}
?>
<br>
activate.php:
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
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
<head>
<link rel="stylesheet" type="text/css" href="css/king.css">
</head>
<br>
<?php
include('config.php');
include('function.php');
session_start();
if (SESSION_IS_REGISTERED('id')&&SESSION_IS_REGISTERED('username')){
if(isset($_POST['submit'])){
$send = '1';
if (!empty($_POST['username'])&&!empty($_POST['password'])&&!empty($_POST['activationkey'])) {
$result = user_login($_POST['username'], $_POST['password']);
if ($result != 'Correct') {
echo "Wrong username/password\n";
} else {
$checkkey = "SELECT * FROM users WHERE username='$_POST[username]'";
$query = mysql_query($checkkey);
while ($key = mysql_fetch_object($query)) {
if ($key->activationkey != $_POST['activationkey']) {
echo "Wrong activation key\n";
} elseif ($key->activationkey == $_POST['activationkey']) {
echo "Account activated please log in again \n\n";
mysql_query ("UPDATE users SET activated='1' WHERE username='$_POST[username]'");
session_unset ();
session_destroy ();
?>
<meta http-equiv="refresh" content="3;URL=index.php" />
<?php
}
}
}
}
}
}
?>
enter your username, password and activation key from your email below<br>
<br>
<form action="?pagina=activate.php" method="POST">
<b>Username:</b> <input type="text" size="16" maxlength="20" name="username"><br>
<?php
if($send==1&&empty($_POST['username'])){
echo"You have to fill in a username";
}
?>
<br>
<b>Password:</b> <input type="password" size="16" maxlength="30" name="password"><br>
<?php
if($send==1&&empty($_POST['password'])){
echo"You have to fill in a username";
}
?>
<br>
<b>activation key:</b> <input type="text" size="16" maxlength="8" name="activationkey"><br>
<?php
if($send==1&&empty($_POST['activationkey'])){
echo"You have to fill in a activation key";
}
?>
<br>
<input type="submit" name="submit" value="Activate">
</form>
<br>
register.php:
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
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
<head>
<link rel="stylesheet" type="text/css" href="css/king.css">
</head>
<br>
<?php
include("config.php");
include("function.php");
$send = 0;
If(isset($_POST['submit'])){
$send = 1;
$check = 1;
if ($_POST['password']==$_POST['cpassword']){
if(!empty($_POST['username'])&&!empty($_POST['password'])&&!empty($_POST['cpassword'])&&!empty($_POST['email'])){
$checkuser = "SELECT username FROM users WHERE username='$_POST[username]'";
$query = mysql_query($checkuser);
if ( mysql_num_rows($query) >= 1 ) {
echo 'username allready exists ';
}
$checkemail = "SELECT email FROM users WHERE email='$_POST[email]'";
$query = mysql_query($checkemail);
if ( mysql_num_rows($query) >= 1 ) {
echo 'email allready exists';
} else {
$salt = generate_salt();
$activationkey = generate_key();
$encrypted = md5(md5($password).$salt);
MYSQL_query("INSERT INTO users(username, password, salt, email, activationkey)
VALUES('$username', '$encrypted', '$salt', '$email', '$activationkey')");
$to = $email;
$subject = "Account activation";
$from = "Webmaster <[email protected]";
$body = "Welcome to Crime investigation,\n\n
You just recieved this email because you have registered at crime investigation\n
if you didn't registered you may delete this message.\n\n
Account information:\n
Username: $username \n
Password: $password \n\n
in order to play you need to activate your account with the activation code below.\n
Activation key:
$activationkey
\n\n\n
Greetings,\n
Crime investigation";
if (mail($to, $subject, $body)) {
echo"You have been registered, you can log in after you have activated your account";
} else {
echo("Oops Something went wrong with sending a email please contact us [email protected]");
}
}
}
}
}
php?>
<center><h3>Registration</h3></center>
<br>
<br>
<form name="register" method="POST" action="?pagina=register.php">
Username: <input type="text" name="username" maxlength="16" size="16"><br>
<?php
if($send==1&&empty($_POST['username'])){
echo"You have to fill in a username";
}
php?>
<br>
Password: <input type="password" name="password" maxlength="20" size="16"><br>
<?php
if($send==1&&empty($_POST['password'])){
echo"You have to fill in a password";
}
php?>
<br>
Confirm password: <input type="password" name="cpassword" maxlength="20" size="16"><br>
<?php
if($send==1&&empty($_POST['cpassword'])){
echo"You have to confirm your password";
}
if($send==1&&!empty($_POST['password'])&&!empty($_POST['cpassword'])&&$_POST['password']!=$_POST['cpassword']){
echo"The passwords you gave do not match";
}
php?>
<br>
Email: <input type="text" name="email" maxlength="50" size="16"><br>
<?php
if($send==1&&empty($_POST['email'])){
echo"You have to fill in an email address to get a activation key";
}
php?>
<br>
<input type="submit" name="submit" value="Submit"><br>
</form>
<br>
function.php:
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
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
<?php
function generate_salt (){
$salt = '';
for ($i = 0; $i < 3; $i++){
$salt .= chr(rand(35, 126));
}
return $salt;
}
function generate_key (){
$activationkey = '';
for ($i = 0; $i < 8; $i++){
$activationkey .= chr(rand(48, 57));
}
return $activationkey;
}
function user_login($username, $password){
$query = "select salt from users where username='$username' limit 1";
$result = mysql_query($query);
$user = mysql_fetch_array($result);
$encrypted = md5(md5($password).$user['salt']);
$query = "select id, username, activated from users where username='$username' and password='$encrypted' and activated='$activated'";
$result = mysql_query($query);
$user = mysql_fetch_array($result);
$numrows = mysql_num_rows($result);
$encrypted_id = md5($user['id']);
$encrypted_name = md5($user['username']);
SESSION_REGISTER('id');
SESSION_REGISTER('username');
$_SESSION['id'] = $id;
$_SESSION['username'] = $username;
$_SESSION['encrypted_id'] = $encrypted_id;
$_SESSION['encrypted_name'] = $encrypted_name;
if ($numrows == 1){
return 'Correct';
} else {
return false;
}
}
function is_authed(){
session_start();
if (isset($_SESSION['id']) && md5($_SESSION['userid']) == $_SESSION['encrypted_name'])
{
return true;
} else {
return false;
}
}
php?>
Code (php)
1
$query = "select id, username, activated from users where username='$username' and password='$encrypted' and activated='$activated'";
Gewijzigd op 01/01/1970 01:00:00 door Burdy
hiervoor kun je ook gebruiken
en kijken of een formulier gepost is doe je met $_SERVER['REQUEST_METHOD']
haal ook even je variabelen buiten quotes in je queries
Edit:
typo :)
Gewijzigd op 01/01/1970 01:00:00 door Erwin Nieuwenhuis