forked from awseeley/mobilepilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login_alt.php
57 lines (45 loc) · 1.11 KB
/
login_alt.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
<?php
require_once("common_db.php");
function check_credentials($username, $password) {
$query = "SELECT shopper_id, sh_password FROM Shopper ";
$query .= "WHERE sh_username = ?";
$dbo = db_connect();
$statement = $dbo->prepare($query);
$statement->execute(array($username));
$row = $statement->fetch();
if ($row[0] > 0) {
if (password_verify($password, $row[1]))
return($row[0]);
else
return(0);
}
else {
return(0);
}
}
function login($username, $password) {
$shopper_id = check_credentials($username, $password);
if ($shopper_id > 0) {
session_regenerate_id(TRUE);
$sessid = session_id();
$dbo = db_connect();
$query = "INSERT INTO Session (id, Shopper_id) VALUES (?,?)";
try {
$statement = $dbo->prepare($query);
$success = $statement->execute(array($sessid, $shopper_id));
}
catch (PDOException $ex) {
error_log($ex->getMessage());
die($ex->getMessage());
}
return (TRUE);
}
else {
return (FALSE);
}
}
function logout() {
session_regenerate_id(TRUE);
session_destroy();
// End the session;
}