From 0555c1a786144102fa1b9381f634138d2bd8c181 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 26 Mar 2017 04:32:27 -0400 Subject: Add various helper functions for user class Added the function to verify and update the user's password. Added the function to confirm and update the user's email address. --- app/class/user.class.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'app/class') diff --git a/app/class/user.class.php b/app/class/user.class.php index b0b3435..9892277 100644 --- a/app/class/user.class.php +++ b/app/class/user.class.php @@ -205,6 +205,51 @@ class user extends agent { return hash("sha256", $passwd . $salt); } + + /* + * Validate the given plain-text password for this user. Returns true if + * correct, false otherwise. + */ + public function validatePasswd(string $passwd) : bool + { + $auth = self::getAuth($passwd, $this->salt); + return $auth == $this->auth; + } + + /* + * Update the auth and salt for this user, given a new plain-text + * password. + */ + public function setPasswd(string $passwd) : void + { + $this->salt = self::getBlob(); + $this->auth = self::getAuth($passwd, $this->salt); + } + + /* + * Validate the email confirmation code for this user. Returns true if + * correct, false otherwise. On success, $this->emailConf is also set + * to 1 + */ + public function verifyEmail(string $ver) : bool + { + if ($ver != $this->emailVer) + return false; + + $this->emailConf = 1; + return true; + } + + /* + * Update the email address for this user. This function will automatically + * reset the emailConf flag and confirmation code for this user as well. + */ + public function setEmail(string $email) : void + { + $this->email = $email; + $this->emailVer = substr(self::getBlob(), 0, 8); + $this->emailConf = 0; + } } ?> -- cgit v1.2.3