-
Notifications
You must be signed in to change notification settings - Fork 14
/
login.php
executable file
·143 lines (121 loc) · 4.08 KB
/
login.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/*
UserCake Version: 2.0.2
http://usercake.com
*/
require_once("models/config.php");
if (!securePage($_SERVER['PHP_SELF'])){die();}
//Prevent the user visiting the logged in page if he/she is already logged in
if(isUserLoggedIn()) { header("Location: account.php"); die(); }
//Forms posted
if(!empty($_POST))
{
$errors = array();
$username = sanitize(trim($_POST["username"]));
$password = trim($_POST["password"]);
$remember_choice = trim($_POST["remember_me"]);
//Perform some validation
//Feel free to edit / change as required
if($username == "")
{
$errors[] = lang("ACCOUNT_SPECIFY_USERNAME");
}
if($password == "")
{
$errors[] = lang("ACCOUNT_SPECIFY_PASSWORD");
}
if(count($errors) == 0)
{
//A security note here, never tell the user which credential was incorrect
if(!usernameExists($username))
{
$errors[] = lang("ACCOUNT_USER_OR_PASS_INVALID");
}
else
{
$userdetails = fetchUserDetails($username);
//See if the user's account is activated
if($userdetails["active"]==0)
{
$errors[] = lang("ACCOUNT_INACTIVE");
}
else
{
//Hash the password and use the salt from the database to compare the password.
$entered_pass = generateHash($password,$userdetails["password"]);
if($entered_pass != $userdetails["password"])
{
//Again, we know the password is at fault here, but lets not give away the combination incase of someone bruteforcing
$errors[] = lang("ACCOUNT_USER_OR_PASS_INVALID");
}
else
{
//Passwords match! we're good to go'
//Construct a new logged in user object
//Transfer some db data to the session object
$loggedInUser = new loggedInUser();
$loggedInUser->email = $userdetails["email"];
$loggedInUser->user_id = $userdetails["id"];
$loggedInUser->hash_pw = $userdetails["password"];
$loggedInUser->currency = $userdetails["currency"];
$loggedInUser->remember_me = $remember_choice;
$loggedInUser->remember_me_sessid = generateHash(uniqid(rand(), true));
$loggedInUser->title = $userdetails["title"];
$loggedInUser->displayname = $userdetails["display_name"];
$loggedInUser->username = $userdetails["user_name"];
$loggedInUser->dogeaddress = $userdetails["dogeaddress"];
$loggedInUser->autodoge = $userdetails["autodoge"];
$loggedInUser->btcaddress = $userdetails["btcaddress"];
$loggedInUser->autobtc = $userdetails["autobtc"];
//Update last sign in
$loggedInUser->updateLastSignIn();
if($loggedInUser->remember_me == 0)
{
$_SESSION["userCakeUser"] = $loggedInUser;
}
else if($loggedInUser->remember_me == 1)
{
updateSessionObj();
$stmt = $mysqli->prepare("INSERT INTO ".$db_table_prefix."sessions VALUES(?, ?, ?)");
$stmt->bind_param("iss", time(), serialize($loggedInUser), $loggedInUser->remember_me_sessid);
$stmt->execute();
$stmt->close();
setcookie("userCakeUser", $loggedInUser->remember_me_sessid, time()+parseLength($remember_me_length));
}
//Redirect to user account page
header("Location: account.php");
die();
}
}
}
}
}
require_once("models/header.php");
?>
<div class="container container_12">
<?php echo resultBlock($errors,$successes); ?>
<div class='loginbox'>
<form name='login' action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>
<p>
<label>Username:</label>
<input type='text' name='username' />
</p>
<p>
<label>Password:</label>
<input type='password' name='password' />
</p>
<p>
<p>
<input type='checkbox' name='remember_me' value='1' />
<label>Remember Me?</label>
</p>
<label> </label>
<input type='submit' value='Login' class='submit' />
</p>
<p class="forgot"><a href='forgot-password.php'>(Forgot Password)</a></p>
</form>
</div>
</div>
<div id='bottom'></div>
</div>
<?php include("footer.php");?>