diff options
author | Malf Furious <m@lfurio.us> | 2017-03-26 04:32:27 -0400 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2017-03-26 04:32:27 -0400 |
commit | 0555c1a786144102fa1b9381f634138d2bd8c181 (patch) | |
tree | 6f896d41cf777c54a9642389563bfab00e1142bb /app/class | |
parent | 173b002d3f9de83f93fc1a0128febcc44410c3d0 (diff) | |
download | scrott-0555c1a786144102fa1b9381f634138d2bd8c181.tar.gz scrott-0555c1a786144102fa1b9381f634138d2bd8c181.zip |
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.
Diffstat (limited to 'app/class')
-rw-r--r-- | app/class/user.class.php | 45 |
1 files changed, 45 insertions, 0 deletions
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; + } } ?> |