diff --git a/code/api.php b/code/api.php index 3c47638..3476aba 100644 --- a/code/api.php +++ b/code/api.php @@ -42,7 +42,7 @@ if (isset($_MGM['user']) && $_MGM['user']['level']==1 && $_MGM['path'][1]=="user $epassword = $result['password']; if (!empty($password)) { $salt = substr(sha1(rand()),0,12); - $epassword = $salt.hash("sha512", $salt.hash("sha512", $password)); + $epassword = $salt.hashPassword($password,hex2bin($salt)); } if ($level=="") $level = $result['level']; diff --git a/code/login.php b/code/login.php index 6c770ae..ccf23bf 100644 --- a/code/login.php +++ b/code/login.php @@ -24,7 +24,7 @@ if (isset($_REQUEST['login'])) { $error = "Invalid login credentials."; } else { $salt = substr($user['password'], 0, 12); - $epassword = $salt.hash("sha512", $salt.hash("sha512", $password)); + $epassword = $salt.hashPassword($password,hex2bin($salt)); if ($epassword!=$user['password']) { $error = "Invalid login credentials."; } else { diff --git a/code/setup.php b/code/setup.php index dad3070..ad4a734 100644 --- a/code/setup.php +++ b/code/setup.php @@ -16,7 +16,7 @@ $result = databaseQuery("SELECT * FROM settings WHERE name='db_version'"); if ($result==NULL) { databaseQuery("CREATE TABLE settings (name TEXT, value TEXT)"); - databaseQuery("INSERT INTO settings (name, value) VALUES ('db_version',%d)", $_MGM['version']); + databaseQuery("INSERT INTO settings (name, value) VALUES ('db_version',%s)", $_MGM['version']); databaseQuery("CREATE VIRTUAL TABLE images USING fts3(user_id INTEGER, hash TEXT, extension TEXT, name TEXT, file_size INTEGER, width INTEGER, height INTEGER, thumb_file_size INTEGER, thumb_width INTEGER, thumb_height INTEGER, tags TEXT, external_data TEXT, ocr TEXT, time INTEGER)"); databaseQuery("CREATE TABLE users (docid INTEGER PRIMARY KEY AUTOINCREMENT, email TEXT, password TEXT, time INTEGER, level INTEGER)"); @@ -31,6 +31,49 @@ if ($result==NULL) { require_once("footer.php"); exit(); +} else { + $info = databaseFetchAssoc($result); + if ($info['value']<=1) { + if (isset($_REQUEST['update_user'])) { + $email = (isset($_REQUEST['email']) ? trim($_REQUEST['email']) : ""); + $password = (isset($_REQUEST['password']) ? trim($_REQUEST['password']) : ""); + + $result = databaseQuery("SELECT * FROM users WHERE email=%s AND level!=0", $email); + $user = databaseFetchAssoc($result); + if ($user==NULL) { + echo "Invalid login credentials."; + } else if ($user['level']!=1) { + echo "Account is not an administrator account."; + } else { + $salt = substr($user['password'], 0, 12); + $epassword = $salt.hash("sha512", $salt.hash("sha512", $password)); + echo $epassword; + if ($epassword!=$user['password']) { + echo "Invalid login credentials."; + } else { + $epassword = $salt.hashPassword($password,hex2bin($salt)); + databaseQuery("UPDATE users SET password=%s WHERE email=%s", $epassword, $email); + databaseQuery("UPDATE settings SET value=%s WHERE name='db_version'", $_MGM['version']); + header("location: ".generateURL()); + exit(); + } + } + } + + require_once("header.php"); + ?> +
Passwords hash system has been changed. Please enter an administrator email and password to update your account. You would be required to update any other account's password once you have completed this step as their account will not be able to function.
+ + + require_once("footer.php"); + exit(); + } } if (isset($_REQUEST['create_user'])) { @@ -41,7 +84,7 @@ if (isset($_REQUEST['create_user'])) { $count = databaseFetchAssoc($result); if ($count['count']==0 && !empty($email) && !empty($password)) { $salt = substr(sha1(rand()),0,12); - $epassword = $salt.hash("sha512", $salt.hash("sha512", $password)); + $epassword = $salt.hashPassword($password,hex2bin($salt)); databaseQuery("INSERT INTO users (email, password, time, level) VALUES (%s,%s,%d,1)", $email, $epassword, $_MGM['time']); setcookie("{$_MGM['CookiePrefix']}user_email", $email, $_MGM['time']+31536000, $_MGM['CookiePath'], $_MGM['CookieDomain']); setcookie("{$_MGM['CookiePrefix']}user_password", hash("sha512", $epassword.$_MGM['time']), $_MGM['time']+31536000, $_MGM['CookiePath'], $_MGM['CookieDomain']); diff --git a/index.php b/index.php index baa67af..dd75354 100644 --- a/index.php +++ b/index.php @@ -17,7 +17,7 @@ error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT); $_MGM = array(); -$_MGM['version'] = "1"; +$_MGM['version'] = "2"; $_MGM['DBType'] = "SQLITE"; // MYSQL, POSTGRESQL, SQLITE. $_MGM['DBPersistent'] = NO; $_MGM['DBHost'] = "localhost"; @@ -72,6 +72,14 @@ function generateURL($path) { return "http".($_MGM['ssl'] ? "s" : "")."://".$_MGM['domain'].(((!$_MGM['ssl'] && $_MGM['port']==80) || ($_MGM['ssl'] && $_MGM['port']==443)) ? "" : ":{$_MGM['port']}").$_MGM['installPath'].$path; } +function hashPassword($password, $salt) { + $hashed = hash("sha512", $salt.$password); + for ($i=0; $i<10000; $i++) { + $hashed = hash("sha512", $salt.hex2bin($hashed)); + } + return $hashed; +} + connectToDatabase(); if (file_exists("code/setup.php")) {