本文整理汇总了PHP中PasswordHash::hashPassword方法的典型用法代码示例。如果您正苦于以下问题:PHP PasswordHash::hashPassword方法的具体用法?PHP PasswordHash::hashPassword怎么用?PHP PasswordHash::hashPassword使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PasswordHash
的用法示例。
在下文中一共展示了PasswordHash::hashPassword方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hashString
/**
* @param $string
* @throws Exception
* @return string
*/
public function hashString($string)
{
$hasher = new \PasswordHash($this->_iterationCount, false);
$hashAndType = $hasher->hashPassword($string);
$check = $hasher->checkPassword($string, $hashAndType['hash']);
if (!$check) {
throw new Exception(Craft::t('Could not hash the given string.'));
}
return $hashAndType;
}
示例2: beforeSave
public function beforeSave()
{
$ph = new PasswordHash(Yii::app()->params['phpass']['iteration_count_log2'], Yii::app()->params['phpass']['portable_hashes']);
//add the password hash if it's a new record
if ($this->getIsNewRecord()) {
$this->user_password = $ph->hashPassword($this->Password);
} elseif (!empty($this->Password) && !empty($this->PasswordConfirm) && $this->Password === $this->PasswordConfirm) {
$this->user_password = $ph->hashPassword($this->Password);
} elseif (!empty($this->ResetPassword)) {
$this->user_password = $ph->hashPassword($this->ResetPassword);
}
//$this->items = implode(', ', $this->items);
return parent::beforeSave();
}
示例3: getUserData
public function getUserData($password)
{
$password = PasswordHash::hashPassword($this->validateInput("guests", $password, "password"));
return $this->loadUser($this->query(DBService::SELECT, "guests", array("COLUMNS" => array("`id`", "`Household name`", "`Has RSVPed`", "`Friend login` as `isFriend`", "(`Ceremony adults invited` + `Ceremony children invited`) as `ceremony invited`", "(`Reception adults invited` + `Reception children invited`) as `reception invited`", "(`Havdalah adults invited` + `Havdalah children invited`) as `havdalah invited`"), "WHERE" => "`password` = '" . $password . "'")));
}
示例4: setPassword
/**
* Set the user's password using the necessary hashing
*
* @param $password
*
* @return bool|string True/False on success or failure, a string if on error.
*/
public function setPassword($password) {
$isvalid = $this->validatePassword($password);
if($isvalid !== true){
// Core validation returned a string.... it's INVALID!
return $isvalid;
}
// hash the password.
$hasher = new \PasswordHash(datastore::HASH_ITERATIONS);
$password = $hasher->hashPassword($password);
// Still here? Then try to set it.
$this->_usermodel->set('password', $password);
$this->_usermodel->set('last_password', DateTime::NowGMT());
return true;
}
示例5: testGeneratedPasswordEncryption
public function testGeneratedPasswordEncryption()
{
$sPassword = PasswordHash::generatePassword();
$sHash = PasswordHash::hashPassword($sPassword);
$this->assertSame(true, PasswordHash::comparePassword($sPassword, $sHash));
}
示例6: setNewPassword
/**
* Set a new password to an user account
*
* @param string $token Password token used to reset the account
* @param string $password New password
* @return bool
*/
public function setNewPassword($token, $password)
{
$changed = false;
$this->_db->beginTransaction();
try {
$tokenData = $this->_db->fetchFirstRequest('getPasswordResetByToken', array(':token' => $token));
if (!empty($tokenData)) {
$hasher = new PasswordHash(8, false);
$hashedPassword = $hasher->hashPassword($password);
if (!empty($hashedPassword)) {
$this->_db->executeRequest('changeUserPassword', array(':password' => $hashedPassword, ':id' => $tokenData['user_id']));
$this->_db->executeRequest('cleanTokens', array(':userId' => $tokenData['user_id']));
$changed = true;
} else {
$this->_messenger->add('error', $this->_lang->get('passwordMiscError'));
}
}
} catch (Exception $e) {
$this->_db->rollBack();
throw $e;
}
$this->_db->commit();
return $changed;
}