-
Notifications
You must be signed in to change notification settings - Fork 12
/
login.php
130 lines (90 loc) · 3.24 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
<?php
include("config.php");
include("functions.php");
include("session.php");
if($session->isLoggedIn()) {
header("Location: index.php");
exit;
}
//TODO add hash to login form to prevent csrf
if(isset($_POST['login'])) {
$error = "";
$username = htmlspecialchars($_POST['username']);
// check username validity
$password = $_POST['password'];
$userinfo = $mysql->query("SELECT * FROM `user` WHERE `username` = '".$mysql->real_escape_string($username)."' LIMIT 1");
if($userinfo->num_rows > 0) {
$error = $hashset;
$row = $userinfo->fetch_assoc();
$hash = $row["passhash"];
$salt = $row["salt"];
$hashset = "sha512:10000:".$salt.":".$hash;
$result = validate_password($password, $hashset);
if($result) {
//username and password good
//$ses = new Session();
$userid = $row["id"];
$session->generateHash();
$sql = "INSERT INTO `logincodes` (
`id`,
`userid`,
`authhash`,
`lastlogin`,
`created`
) VALUES (
NULL,
'".$mysql->real_escape_string($userid)."',
'".$mysql->real_escape_string($session->hash)."',
'".time()."',
'".time()."'
)";
if($mysql->query($sql)) {
$id = $mysql->insert_id;
//$error = $session->hash;
$session->setUser($userid);
$session->setID($id);
$session->setPHPSession();
//redirect to homepage
header("Location: index.php");
} else {
$error = "database error. try again";
}
} else {
//password wrong
$error = "username or password wrong";
}
} else {
$error = "username or password wrong";
}
}
htmlHeader("login - synccit");
?>
<div class="fourcol">
<h2>login</h2>
</div>
<div class="fourcol">
<span class="error"><?php echo $error; ?></span><br /><br />
<form action="<?php echo LOGINURL; ?>" method="post">
<input type="hidden" name="hash" value="<?php echo $hash; ?>" />
<label for="username">username</label><br />
<input type="text" id="username" name="username" value="<?php echo $username; ?>" class="textcreate" />
<br /><br />
<label for="password">password</label><br />
<input type="password" id="password" name="password" value="" class="textcreate" />
<br /><br />
<input type="submit" value="login" name="login" class="submit" />
</form>
<br /><br />
<span class="resetlink"><a href="<?php echo RESETURL; ?>">reset password</a></span>
</div>
<div class="fourcol last">
<p class="aside">
<span class="bold">Privacy</span>:<br /><br />
We won't reveal your username, password, or email to any third parties.
We won't spam your email or send out any unsolicited emails without a quick and easy way to unsubscribe.
Link information may be used for stats and other neat things, but the information will be kept anonymous.
For added security, use a different username and password than your reddit account.
</p>
</div>
<?php
htmlFooter();