本文整理汇总了PHP中password_needs_rehash函数的典型用法代码示例。如果您正苦于以下问题:PHP password_needs_rehash函数的具体用法?PHP password_needs_rehash怎么用?PHP password_needs_rehash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了password_needs_rehash函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: runHash
private static function runHash($para, $rehash = false)
{
if (empty($para)) {
return false;
}
$option = [];
if (!empty(self::$_salt)) {
$option['salt'] = self::$_salt;
}
if (!empty(self::$_cost)) {
$option['cost'] = self::$_cost;
}
if (!empty($option)) {
if ($rehash) {
return password_needs_rehash($para, self::$_algo, $option);
} else {
return password_hash($para, self::$_algo, $option);
}
} else {
if ($rehash) {
return password_needs_rehash($para, self::$_algo);
} else {
return password_hash($para, self::$_algo);
}
}
}
示例2: _login
/**
* Logs a user in.
*
* @param string $username username
* @param string $password password
* @param boolean $remember enable autologin
* @return boolean
*/
protected function _login($user, $password, $remember)
{
$user = $this->_load_user($user);
if (!$user) {
return false;
}
if (!$user->roles->has('login')) {
return false;
}
$hash = $this->password($user);
// If the passwords match, perform a login
if (!password_verify($password, $hash)) {
return false;
}
if (!$this->_config['hash_algorithm']) {
throw new Kohana_Exception('A valid hash algorithm must be set in your auth config.');
}
$hash_options = Arr::get($this->_config, 'hash_options', array());
// If options changed rehash password and update in database
if (password_needs_rehash($hash, $this->_config['hash_algorithm'], $hash_options)) {
$user->password = password_hash($password, $algorithm, $options);
}
if ($remember === TRUE) {
$this->remember($user);
}
// Finish the login
$this->complete_login($user);
return true;
}
示例3: Authenticate
public function Authenticate(array $params)
{
if (!isset($params['username']) || !isset($params['password']) || empty($params['db'])) {
throw new Exception('DatabaseAuthenticator expects a connection, a username and a password');
}
$this->db = $params['db'];
$query = 'SELECT u.username, u.password FROM users u
LEFT JOIN user_company_access uca ON (u.username=uca.username)
LEFT JOIN system_companies sc ON (uca.usercompanyid=sc.id)
WHERE sc.enabled AND uca.enabled AND u.username=?';
$query_params = array($params['username']);
$test = $this->db->GetAssoc($query, $query_params);
if ($test !== false && !is_null($test)) {
// try against default hash
if (password_verify($params['password'], $test[$params['username']])) {
if (password_needs_rehash($test[$params['username']], PASSWORD_DEFAULT)) {
$this->update_hash($params['password'], $params['username']);
}
return TRUE;
}
// try against hashed md5
if (password_verify(md5($params['password']), $test[$params['username']])) {
// update hash
$this->update_hash($params['password'], $params['username']);
return TRUE;
}
}
return FALSE;
}
示例4: session
function session($user, $pass)
{
$user_file = 'config/users/' . $user . '.ini';
if (!file_exists($user_file)) {
return $str = '<li>Username not found in our record.</li>';
}
$user_enc = user('encryption', $user);
$user_pass = user('password', $user);
$user_role = user('role', $user);
if ($user_enc == "password_hash") {
if (password_verify($pass, $user_pass)) {
if (password_needs_rehash($user_pass, PASSWORD_DEFAULT)) {
update_user($user, $pass, $user_role);
}
$_SESSION[config("site.url")]['user'] = $user;
header('location: admin');
} else {
return $str = '<li>Your username and password mismatch.</li>';
}
} else {
if (old_password_verify($pass, $user_enc, $user_pass)) {
update_user($user, $pass, $user_role);
$_SESSION[config("site.url")]['user'] = $user;
header('location: admin');
} else {
return $str = '<li>Your username and password mismatch.</li>';
}
}
}
示例5: pwdNeedsRehash
/**
* Checks if the given hash matches the given options
*
* @param string $sPwd
* @param string $sHash
*
* @return mixed (string | boolean) Returns the new password if the password needs to be rehash, otherwise FALSE
*/
public static function pwdNeedsRehash($sPwd, $sHash)
{
if (password_needs_rehash($sHash, self::PWD_ALGORITHM, self::$_aPwdOptions)) {
return self::hashPwd($sPwd);
}
return false;
}
示例6: needsRehash
public function needsRehash($hash = null)
{
if (is_null($hash)) {
$hash = $this->value;
}
return password_needs_rehash($hash, PASSWORD_BCRYPT, ['cost' => 10]);
}
示例7: checkPassword
public function checkPassword($password)
{
/*
* If there is no password hashing mechanism, we should abort ASAP. Since
* nothing the application could do then would make any sense.
*/
if (!function_exists('password_hash')) {
throw new PrivateException('Password hashing algorithm is missing. Please check your PHP version', 1602270012);
}
/*
* If the password doesn't match, then we need to tell the user that whatever
* he wrote into the form was not acceptable.
*/
if (!password_verify($password, $this->password)) {
return false;
}
/*
* Getting here means the password was correct, we can now ensure that it's
* up to speed with the latest encryption and rehash it in case it's needed.
*/
if (password_needs_rehash($this->password, PASSWORD_DEFAULT)) {
$this->password = password_hash($password, PASSWORD_DEFAULT);
$this->store();
}
return true;
}
示例8: userLoad
public function userLoad($login, $password, $uid = -1)
{
// Load a compatibility wrapper for PHP versions prior to 5.5.0
if (!function_exists("password_hash")) {
include "app/inc/password_compat.php";
}
$this->prepare("userQuery", "SELECT U.password, U.uid FROM `tbl_users` U where ( U.login = :login OR U.uid = :uid )");
$this->bindValue("userQuery", ":login", $login, \PDO::PARAM_STR);
$this->bindValue("userQuery", ":uid", $uid, \PDO::PARAM_INT);
$user = $this->execute("userQuery");
if (sizeof($user) == 0) {
return FALSE;
} else {
$user = $user[0];
}
if (password_verify($password, $user['password'])) {
// Check if the password requires improvement
if (password_needs_rehash($user['password'], PASSWORD_DEFAULT)) {
$this->userChangePW($user['uid'], $password);
}
} elseif ($user['password'] == md5($password)) {
$this->userChangePW($user['uid'], $password);
} else {
return FALSE;
}
$this->userSession($user['uid']);
return $user['uid'];
}
示例9: rehash
public static function rehash($value)
{
if (password_needs_rehash($value, PASSWORD_BCRYPT)) {
return password_hash($value, PASSWORD_BCRYPT);
}
return $value;
}
示例10: preAnswer
/**
* Hash the answer
*
* @param string $value Answer to question
* @return string Hashed answer
*/
public function preAnswer($value)
{
if (password_needs_rehash($value, PASSWORD_DEFAULT) === true) {
$value = password_hash($value, PASSWORD_DEFAULT);
}
return $value;
}
示例11: check_admin_login
function check_admin_login($username, $password)
{
$query = $this->db->get_where('admin_users', array('username' => $username));
if ($query->num_rows() > 0) {
$row = $query->row();
} else {
return array(false, 'invalid_credentials');
}
if (intval($row->active) !== 1) {
return array(false, 'user_revoked');
}
if (intval($row->failed_access) >= 5) {
return array(false, 'user_locked');
}
if (password_verify($password, $row->password)) {
// Check if a newer hashing algorithm is available or the cost has changed
if (password_needs_rehash($row->password, PASSWORD_DEFAULT)) {
// If so, create a new hash, and replace the old one
$newHash = password_hash($password, PASSWORD_DEFAULT);
$this->db->where('username', $username);
$this->db->update('admin_users', array('password' => $newHash));
}
$this->db->where('username', $username);
$this->db->update('admin_users', array('failed_access' => 0));
return array(true, $username);
} else {
$this->db->where('username', $username);
$this->db->update('admin_users', array('failed_access' => $row->failed_access + 1));
return array(false, 'invalid_credentials');
}
}
示例12: doesItNeedRehashing
public static function doesItNeedRehashing($hash)
{
if (!is_string($hash)) {
return false;
}
return password_needs_rehash($hash, PASSWORD_DEFAULT);
}
示例13: needsRehash
/**
* Does this password require rehashing
*
* @param $hash string
* @return boolean
**/
function needsRehash($hash)
{
if (Hashing::isSupported()) {
return password_needs_rehash($hash, PASSWORD_BCRYPT);
}
return false;
}
示例14: needsNewHash
public function needsNewHash()
{
if (password_needs_rehash($this->password, PASSWORD_DEFAULT)) {
return true;
}
return false;
}
示例15: authenticate
public function authenticate($username = null, $password = null)
{
if (is_null($username) || is_null($password)) {
return false;
}
$db = UniversalConnect::doConnect();
$usernameToCheck = $db->real_escape_string(trim($username));
$passwordToCheck = $db->real_escape_string(trim($password));
$query = "SELECT userkey, password, usertype FROM users WHERE userid=\"{$usernameToCheck}\" LIMIT 1";
$result = $db->query($query) or die($db->error . $query);
if ($result->num_rows < 1) {
return false;
}
while ($row = $result->fetch_assoc()) {
if (password_verify($passwordToCheck, $row["password"])) {
if (password_needs_rehash($row["password"], PASSWORD_DEFAULT)) {
$newHash = password_hash($passwordToCheck, PASSWORD_DEFAULT);
$query = "UPDATE users SET password=\"{$newHash}\" WHERE userkey=" . $row["userkey"];
$db->query($query);
}
return true;
} else {
return false;
}
}
}