-
Notifications
You must be signed in to change notification settings - Fork 0
/
login2.php
34 lines (26 loc) · 932 Bytes
/
login2.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
<?
// require common code
require_once("hidden/basic.php");
// escape username to avoid SQL injection attacks
$useremail = mysql_real_escape_string($_POST["email"]);
// prepare SQL
$sql = "SELECT * FROM users WHERE email='$useremail'";
// execute query
$result = mysql_query($sql);
// if we found user, check password
if (mysql_num_rows($result) == 1)
{
// grab row
$row = mysql_fetch_array($result);
// compare hash of user's input against hash that's in database
if (crypt($_POST["password"], $row["passwordHash"]) == $row["passwordHash"])
{
// remember that user's now logged in by caching user's ID in session
$_SESSION["id"] = $row["userID"];
// redirect to homepage
redirect("index.html");
}
}
// else report error
apologize("Invalid username and/or password!");
?>