-
Notifications
You must be signed in to change notification settings - Fork 6
/
AuthController.php
75 lines (68 loc) · 1.71 KB
/
AuthController.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* Authentacation
*/
class Auth_Controller
{
function fn_Login($conn, $username, $password)
{
try
{
$query = "SELECT * FROM users WHERE username = :username AND password = :password";
$stmt = $conn->prepare($query);
$stmt->execute(
array(
'username' => $username,
'password' => md5($password)
) );
$count = $stmt->rowCount();
if ($count == "1")
{
return "success";
}
else{
return "Failed to login ";
}
}
catch (Exception $e)
{
return "Failed to login " .$e->getMessage();
}
}
function insert_2authfactorlogs($conn,$username, $hash)
{
try
{
$now = new DateTime();
$dt = $now->format('Y-m-d H:i:s');
$dt1 = $now->format('m-Y-d H:i:s');
$dt2 = $now->format('d-m-Y H:i:s');
$dttime = $now->format('Y-m-d H:i:s');
$id = round($dt).round($dt1).round($dt2).round(microtime(true));
$sql = "INSERT INTO 2authfactorlogs (2authID, username, status, dt, hash, try, duration)
VALUES ('$id', '$username', 'active', '$dttime', '$hash', 5, 900)";
$conn->exec($sql);
return "success";
}
catch (Exception $e)
{
return "Failed to login " .$e->getMessage();
}
}
function insert_2authfactor_func($conn,$username, $code)
{
try
{
$now = new DateTime();
$dttime = $now->format('Y-m-d H:i:s');
$sql = "INSERT INTO 2authfactor (userid, status, code, dt, duration)
VALUES ('$username', 'active', '$code', '$dttime', '900')";
$conn->exec($sql);
return "success";
}
catch (Exception $e)
{
return "Failed to login " .$e->getMessage();
}
}
}