Hashed password (****)
Hoe komt dit?
Code (php)
1
2
3
4
5
2
3
4
5
<?php
require_once("includes/session.php");
require_once("includes/connection.php");
require_once("includes/functions.php");
?>
require_once("includes/session.php");
require_once("includes/connection.php");
require_once("includes/functions.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
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
<?php
if(logged_in()) {
redirect_to('staff.php');
}
include_once("includes/form_functions.php");
if(isset($_POST['submit'])) {
$errors = array();
$required_fields = array('username', 'password');
$errors = array_merge($errors, check_required_fields($required_fields, $_POST));
$fields_with_lengths = array('username' => 30, 'password' => 30);
$errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST));
$username = trim(mysql_prep($_POST['username']));
$password = trim(mysql_prep($_POST['password']));
$hashed_password = sha1($password);
if(empty($errors)) {
$query = "SELECT id, username ";
$query .= "FROM users ";
$query .= "WHERE username = '{$username}' ";
$query .= "AND hashed_password = '{$hashed_password}' ";
$query .= "LIMIT 1";
$result_set = mysql_query($query);
confirm_query($result_set);
if(mysql_num_rows($result_set) == 1) {
$found_user = mysql_fetch_array($result_set);
$_SESSION['user_id'] = $found_user['id'];
$_SESSION['username'] = $found_user['username'];
redirect_to('staff.php');
} else {
$message = "Gebruikersnaam en/of wachtwoord is incorrect.<br />";
}
} else {
if(count($errors) == 1) {
$message = "There was 1 error in the form.";
} else {
$message = "There were ". count($errors) . " errors in the form.";
}
}
} else {
// Submit failed
if(isset($_GET['logout']) && $_GET['logout'] == 1) {
$message = "Je bent nu afgemeld";
}
$username = "";
$password = "";
}
?>
if(logged_in()) {
redirect_to('staff.php');
}
include_once("includes/form_functions.php");
if(isset($_POST['submit'])) {
$errors = array();
$required_fields = array('username', 'password');
$errors = array_merge($errors, check_required_fields($required_fields, $_POST));
$fields_with_lengths = array('username' => 30, 'password' => 30);
$errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST));
$username = trim(mysql_prep($_POST['username']));
$password = trim(mysql_prep($_POST['password']));
$hashed_password = sha1($password);
if(empty($errors)) {
$query = "SELECT id, username ";
$query .= "FROM users ";
$query .= "WHERE username = '{$username}' ";
$query .= "AND hashed_password = '{$hashed_password}' ";
$query .= "LIMIT 1";
$result_set = mysql_query($query);
confirm_query($result_set);
if(mysql_num_rows($result_set) == 1) {
$found_user = mysql_fetch_array($result_set);
$_SESSION['user_id'] = $found_user['id'];
$_SESSION['username'] = $found_user['username'];
redirect_to('staff.php');
} else {
$message = "Gebruikersnaam en/of wachtwoord is incorrect.<br />";
}
} else {
if(count($errors) == 1) {
$message = "There was 1 error in the form.";
} else {
$message = "There were ". count($errors) . " errors in the form.";
}
}
} else {
// Submit failed
if(isset($_GET['logout']) && $_GET['logout'] == 1) {
$message = "Je bent nu afgemeld";
}
$username = "";
$password = "";
}
?>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<h2>Aanmelden</h2>
<?php if(!empty($message)) { echo "<p class=\"message\">" . $message . "</p>"; } ?>
<?php if(!empty($errors)) { display_errors($errors); } ?>
<form action="login.php" method="post">
<table>
<tr>
<td>Gebruikersnaam:</td>
<td><input type="text" name="username" maxlength="30" value="<?php
echo htmlentities($username); ?>" /></td>
</tr>
<tr>
<td>Wachtwoord:</td>
<td><input type="text" name="password" maxlength="30" value="<?php
echo htmlentities($password); ?>" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Log in" /></td>
</tr>
</table>
</form>
<?php if(!empty($message)) { echo "<p class=\"message\">" . $message . "</p>"; } ?>
<?php if(!empty($errors)) { display_errors($errors); } ?>
<form action="login.php" method="post">
<table>
<tr>
<td>Gebruikersnaam:</td>
<td><input type="text" name="username" maxlength="30" value="<?php
echo htmlentities($username); ?>" /></td>
</tr>
<tr>
<td>Wachtwoord:</td>
<td><input type="text" name="password" maxlength="30" value="<?php
echo htmlentities($password); ?>" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Log in" /></td>
</tr>
</table>
</form>
Gewijzigd op 16/01/2012 10:49:38 door Jos Vermassen
Met hashed bedoel je dat je van die rondjes in het input veld krijgt? Dan moet je type="password" meegeven aan dat input.
Wouter J op 16/01/2012 10:49:10:
Met hashed bedoel je dat je van die rondjes in het input veld krijgt? Dan moet je type="password" meegeven aan dat input.
ah lol dat is het gewoon, dom van me :D
Bedankt!