-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthenticate.php
More file actions
65 lines (53 loc) · 1.93 KB
/
Copy pathauthenticate.php
File metadata and controls
65 lines (53 loc) · 1.93 KB
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
<?php
/**
* Created by PhpStorm.
* @author Zachary Hughes <zhughes3@gmail.com>
* Date: 3/16/2016
* Time: 12:45 PM
* Description: Authenticate hashed and salted password.
*/
require_once 'login.php';
$connection = new mysqli($db_host, $user, $pass, $db);
if ($connection->connect_error) {
die($connection->connect_error);
}
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
$un_temp = mysql_entities_fix_string($connection, $_SERVER['PHP_AUTH_USER']);
$pw_temp = mysql_entities_fix_string($connection, $_SERVER['PHP_AUTH_PW']);
$query = "SELECT * FROM users WHERE username = '$un_temp'";
$result = $connection->query($query);
if (!result) {
die($connection->error);
} elseif ($result->num_rows) {
$row = $result->fetch_array(MYSQLI_NUM);
$result->close();
$token = hash('ripemd128', "$iniSalt$pw_temp$endSalt");
if ($token == $row[3]) {
session_start();
$_SESSION['username'] = $un_temp;
$_SESSION['password'] = $pw_temp;
$_SESSION['firstname'] = $row[0];
$_SESSION['lastname'] = $row[1];
echo "$row[0] $row[1] : Hi $row[0],
you are now logged in as '$row[2]'";
die("<p><a href = 'continue.php'>Click here to continue. . .</a></p>")
} else {
die("Invalid username/password combination");
}
} else {
header('WWW-Authenticate: Basic realm = "Restricted Section"');
header('HTTP/1.0 401 Unauthorized');
die("Please enter your username and password");
}
$connection->close();
function mysql_entities_fix_string($conn, $string) {
return htmlentities(mysql_fix_string($conn, $string));
}
function mysql_fix_string($conn, $string) {
if (get_magic_quotes_gpc()) {
$string = stripslashes($string);
}
return $conn->real_escape_string($string);
}
}
?>