-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfoShareAuthentication.php
More file actions
59 lines (50 loc) · 1.66 KB
/
infoShareAuthentication.php
File metadata and controls
59 lines (50 loc) · 1.66 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
<?php
abstract class AUTHENTICATION_STATUS
{
const NOT_REGISTERED = 0;
const WRONG_CREDENTIALS = -1;
const NOT_CONFIRMED = -2;
}
abstract class REGISTRATION_STATUS
{
const SUCCESS = 0;
const ALREADY_REGISTERED = 1;
}
function authenticateUser($dbhandle, $email, $password){
if(getUserByEmail($dbhandle, $email) == null){
return AUTHENTICATION_STATUS::NOT_REGISTERED;
}
$sql = "SELECT * FROM users WHERE email = '".$email."' AND password = '".$password."' limit 1";
$query = mysqli_query($dbhandle, $sql) or die(mysqli_error());
$user = mysqli_fetch_object($query);
if($user == null){
return AUTHENTICATION_STATUS::WRONG_CREDENTIALS;
}else if($user->confirmed){
return $user->id;
}else{
return AUTHENTICATION_STATUS::NOT_CONFIRMED;
}
}
function registerUser($dbhandle, $email, $password, $date){
if(getUserByEmail($dbhandle, $email) != null){
return REGISTRATION_STATUS::ALREADY_REGISTERED;
}
$hash = hashPassword($password);
$sql = "INSERT INTO users (email, password, registrationDate) VALUES ('".$email."','".$hash."','".$date."')";
mysqli_query($dbhandle, $sql) or die(mysqli_error());
sendEmail($email);
return REGISTRATION_STATUS::SUCCESS;
}
function getUserByEmail($dbhandle, $email){
$sql = "SELECT * FROM users WHERE email = '".$email."' limit 1";
$query = mysqli_query($dbhandle, $sql) or die(mysqli_error());
return mysqli_fetch_object($query);
}
function confirmUserByEmail($dbhandle, $email){
$sql = "UPDATE users SET confirmed=1 WHERE email ='".$email."'";
return mysqli_query($dbhandle, $sql) or die(mysqli_error());
}
function hashPassword($password){
return md5($password);
}
?>