summaryrefslogtreecommitdiffstats
path: root/web/lib/acctfuncs.inc.php
diff options
context:
space:
mode:
authorcanyonknight <canyonknight@gmail.com>2012-05-23 15:30:21 -0400
committerLukas Fleischer <archlinux@cryptocrack.de>2012-07-06 11:27:00 +0200
commit82d234c4d559a80ab33b682e004e5991f65a8017 (patch)
tree6e4031d3148a49e56d36aa6da48a76b543f231e0 /web/lib/acctfuncs.inc.php
parentf93f1a652ffec5cca0f9bdfb7895a5439382bd2a (diff)
downloadaurweb-82d234c4d559a80ab33b682e004e5991f65a8017.tar.xz
passreset.php: Pull out DB code
* Move DB code in passreset.php to new functions in acctfuncs.inc.php * Centralization of DB code important in a future transition to PDO interface Signed-off-by: canyonknight <canyonknight@gmail.com> Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Diffstat (limited to 'web/lib/acctfuncs.inc.php')
-rw-r--r--web/lib/acctfuncs.inc.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php
index ecb9f99..31c43db 100644
--- a/web/lib/acctfuncs.inc.php
+++ b/web/lib/acctfuncs.inc.php
@@ -580,6 +580,40 @@ function add_tu_proposal($agenda, $user, $votelength, $submitteruid, $dbh=NULL)
}
+# Add a reset key for a specific user
+function create_resetkey($resetkey, $uid, $dbh=NULL) {
+ if(!$dbh) {
+ $dbh = db_connect();
+ }
+ $q = "UPDATE Users ";
+ $q.= "SET ResetKey = '" . $resetkey . "' ";
+ $q.= "WHERE ID = " . $uid;
+ db_query($q, $dbh);
+}
+
+# Change a password and save the salt only if reset key and email are correct
+function password_reset($hash, $salt, $resetkey, $email, $dbh=NULL) {
+ if(!$dbh) {
+ $dbh = db_connect();
+ }
+ $q = "UPDATE Users ";
+ $q.= "SET Passwd = '$hash', ";
+ $q.= "Salt = '$salt', ";
+ $q.= "ResetKey = '' ";
+ $q.= "WHERE ResetKey != '' ";
+ $q.= "AND ResetKey = '".db_escape_string($resetkey)."' ";
+ $q.= "AND Email = '".db_escape_string($email)."'";
+ $result = db_query($q, $dbh);
+
+ if (!mysql_affected_rows($dbh)) {
+ $error = __('Invalid e-mail and reset key combination.');
+ return $error;
+ } else {
+ header('Location: passreset.php?step=complete');
+ exit();
+ }
+}
+
function good_passwd($passwd) {
if ( strlen($passwd) >= PASSWD_MIN_LEN ) {
return true;