-
Notifications
You must be signed in to change notification settings - Fork 2
/
authenticate.php
58 lines (49 loc) · 1.35 KB
/
authenticate.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
<?php require_once("includes/session.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php require_once("includes/connection.php"); ?>
<?php
$errors = array();
//Form validation
$required_fields = array("username", "password");
foreach ($required_fields as $fieldname)
{
if (!isset($_POST[$fieldname]) || empty($_POST[$fieldname]))
{
$errors[] = $fieldname;
}
}
$fields_with_lengths = array("username" => 30, "password" => 30);
foreach ($fields_with_lengths as $fieldname => $maxlength)
{
if (strlen(trim(mysql_prep($_POST["$fieldname"]))) > $maxlength)
{
$errors[] = $fieldname;
}
}
if (!empty($errors))
{
redirect_to("login.php");
}
?>
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
$username = mysql_prep(htmlentities($_POST["username"]));
$password = mysql_prep(htmlentities($_POST["password"]));
?>
<?php
$hashed_password = sha1($password);
if (authenticate_user($username, $hashed_password))
{
//Success!
$_SESSION['username'] = $username;
redirect_to("staff.php");
}
//Display error message.
echo "<p>User/password combination invalid!</p>";
?>
<?php
mysql_close($connection);
?>