diff options
author | Malf Furious <m@lfurio.us> | 2016-02-01 19:18:55 -0500 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2016-02-01 19:18:55 -0500 |
commit | c776b36fd884808435dd1208f0dd9a57216b3927 (patch) | |
tree | 0ab975326c33946452b03ae715a5808fdf9757aa /app/class/user.class.php | |
parent | 8640c13c934ff3e6d907b1e335edb83da088a2ca (diff) | |
download | scrott-c776b36fd884808435dd1208f0dd9a57216b3927.tar.gz scrott-c776b36fd884808435dd1208f0dd9a57216b3927.zip |
Implement authentication helper functions in User class
Added function to initialize a User object by username wrather than GUID.
Added function to validate a user-supplied plain-text password for a given user
Diffstat (limited to 'app/class/user.class.php')
-rw-r--r-- | app/class/user.class.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/app/class/user.class.php b/app/class/user.class.php index 6bce26c..bd2e174 100644 --- a/app/class/user.class.php +++ b/app/class/user.class.php @@ -28,6 +28,21 @@ class User extends Object } /* + * Initialize object by username + */ + function initByUsername($username) + { + $query = "SELECT guid FROM object WHERE type = 'user' AND name = '" . $this->db->esc($username) . "'"; + $result = $this->db->query($query); + + if (count($result) == 0) + return false; + + $this->loadObj($result[0]['guid']); + return true; + } + + /* * Get all users -- ordered by name, ascending */ function getAllUsers_orderByName() @@ -96,6 +111,15 @@ class User extends Object return true; } + + /* + * Validate the password for this user. Returns true if correct, false otherwise + */ + function validatePassword($password) + { + $key = $this->getKey($password, $this->salt); + return $key == $this->key; + } } ?> |