本文整理汇总了PHP中PassHash::authenticate方法的典型用法代码示例。如果您正苦于以下问题:PHP PassHash::authenticate方法的具体用法?PHP PassHash::authenticate怎么用?PHP PassHash::authenticate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PassHash
的用法示例。
在下文中一共展示了PassHash::authenticate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkOldPass
/**
* Check the old pass is Ok or not
*
* @param array $attribute
* @param array $params
* @return boolean
*/
public function checkOldPass($attribute, $params)
{
$u = User::model()->findbyPk(user()->id);
if ($u != null) {
if (!PassHash::authenticate($this->old_password, $u->password)) {
$this->addError($attribute, t('cms', 'Old password is not correct!'));
return false;
}
} else {
$this->addError($attribute, t('cms', 'No User Found!'));
return false;
}
}
示例2: authenticate
/**
* This function check the user Authentication
*
* @return int
*/
public function authenticate()
{
// Check username based on email or username
$username = strtolower($this->username);
if (strpos($username, '@') !== false) {
$user = User::model()->find('LOWER(email)=?', array($username));
} else {
$user = User::model()->find('LOWER(username)=?', array($username));
}
if ($user === null) {
$this->errorCode = self::ERROR_USERNAME_INVALID;
} else {
if (!PassHash::authenticate($this->password, $user->password)) {
$this->errorCode = self::ERROR_PASSWORD_INVALID;
} else {
if ($user->status == ConstantDefine::USER_STATUS_ACTIVE) {
$this->_id = $user->user_id;
$this->username = $user->username;
//If the site allow auto Login, create token to recheck for Cookies
if (Yii::app()->user->allowAutoLogin) {
$autoLoginToken = sha1(uniqid(mt_rand(), true));
$this->setState('autoLoginToken', $autoLoginToken);
$connection = Yii::app()->db;
//delete old keys
$command = $connection->createCommand('DELETE FROM {{autologin_tokens}} WHERE user_id=:user_id');
$command->bindValue(':user_id', $user->user_id, PDO::PARAM_STR);
$command->execute();
//set new
$command = $connection->createCommand('INSERT INTO {{autologin_tokens}}(user_id,token) VALUES(:user_id,:token)');
$command->bindValue(':user_id', $user->user_id, PDO::PARAM_STR);
$command->bindValue(':token', $autoLoginToken, PDO::PARAM_STR);
$command->execute();
}
//Start to set the recent_login time for this user
$user->recent_login = time();
$user->save();
//Set additional User Information
//Set the Error Code to None for Success
$this->errorCode = self::ERROR_NONE;
} else {
$this->errorCode = ConstantDefine::USER_ERROR_NOT_ACTIVE;
}
}
}
unset($user);
return $this->errorCode;
}