public function isValid() { // get db class $db = Knowledgeroot_Registry::get('db'); // get user from db $user = $db->fetchRow("SELECT id, password FROM " . $db->quoteIdentifier('user') . " WHERE login=? AND active=?", array($this->username, Knowledgeroot_Db::true())); // check password hashes if ($user && Knowledgeroot_Password::verify($this->password, $user['password'])) { $this->isValid = true; return true; } return false; }
public function setPassword($password) { $hash = new Knowledgeroot_Password($password); $this->passwordHash = $hash->getHash(); }
/** * verify password with hash value * * @param type $password * @param type $hash * @return bool */ public static function verify($password, $hash) { // get old settings from hash $hashArr = explode("\$", $hash); $method = $hashArr[1]; $rotation = $hashArr[2]; $salt = $hashArr[3]; $pwHash = $hashArr[4]; // generate hash with old values $verifyHash = Knowledgeroot_Password::generateHash($password, $method, $rotation, $salt); return $hash == $verifyHash; }