summaryrefslogtreecommitdiff
path: root/inc/mod/auth.php
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2013-07-24 16:24:20 -0400
committerczaks <marcin@6irc.net>2013-07-24 16:24:20 -0400
commit114e34eea5068af178761d591fdb8718ca2ae8ca (patch)
treed352fe4fd13df8b89232d1d889b567cb2db8faca /inc/mod/auth.php
parent4e609da2b75f5fe6d694617735cad77014a504f1 (diff)
parent33a1c00bd51618a4b54fd6fdab721aaaa03bfd33 (diff)
Merge branch 'master' of https://github.com/savetheinternet/Tinyboard
Conflicts: install.php
Diffstat (limited to 'inc/mod/auth.php')
-rw-r--r--inc/mod/auth.php34
1 files changed, 21 insertions, 13 deletions
diff --git a/inc/mod/auth.php b/inc/mod/auth.php
index 173190ab..1bc27dff 100644
--- a/inc/mod/auth.php
+++ b/inc/mod/auth.php
@@ -29,6 +29,11 @@ function mkhash($username, $password, $salt = false) {
return $hash;
}
+function generate_salt() {
+ mt_srand(microtime(true) * 100000 + memory_get_usage(true));
+ return md5(uniqid(mt_rand(), true));
+}
+
function login($username, $password, $makehash=true) {
global $mod;
@@ -37,20 +42,23 @@ function login($username, $password, $makehash=true) {
$password = sha1($password);
}
- $query = prepare("SELECT `id`,`type`,`boards` FROM `mods` WHERE `username` = :username AND `password` = :password LIMIT 1");
+ $query = prepare("SELECT `id`, `type`, `boards`, `password`, `salt` FROM `mods` WHERE `username` = :username");
$query->bindValue(':username', $username);
- $query->bindValue(':password', $password);
$query->execute() or error(db_error($query));
- if ($user = $query->fetch()) {
- return $mod = array(
- 'id' => $user['id'],
- 'type' => $user['type'],
- 'username' => $username,
- 'hash' => mkhash($username, $password),
- 'boards' => explode(',', $user['boards'])
- );
- } else return false;
+ if ($user = $query->fetch(PDO::FETCH_ASSOC)) {
+ if ($user['password'] === hash('sha256', $user['salt'] . $password)) {
+ return $mod = array(
+ 'id' => $user['id'],
+ 'type' => $user['type'],
+ 'username' => $username,
+ 'hash' => mkhash($username, $user['password']),
+ 'boards' => explode(',', $user['boards'])
+ );
+ }
+ }
+
+ return false;
}
function setCookies() {
@@ -104,10 +112,10 @@ if (isset($_COOKIE[$config['cookies']['mod']])) {
exit;
}
- $query = prepare("SELECT `id`, `type`, `boards`, `password` FROM `mods` WHERE `username` = :username LIMIT 1");
+ $query = prepare("SELECT `id`, `type`, `boards`, `password` FROM `mods` WHERE `username` = :username");
$query->bindValue(':username', $cookie[0]);
$query->execute() or error(db_error($query));
- $user = $query->fetch();
+ $user = $query->fetch(PDO::FETCH_ASSOC);
// validate password hash
if ($cookie[1] !== mkhash($cookie[0], $user['password'], $cookie[2])) {