当前位置: 首页>>代码示例>>PHP>>正文


PHP password_needs_rehash函数代码示例

本文整理汇总了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);
         }
     }
 }
开发者ID:keigonec,项目名称:XiiBackend,代码行数:26,代码来源:TraitData.php

示例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;
 }
开发者ID:despark,项目名称:kohana,代码行数:37,代码来源:Jam.php

示例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;
 }
开发者ID:uzerpllp,项目名称:uzerp,代码行数:29,代码来源:DatabaseAuthenticator.php

示例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>';
        }
    }
}
开发者ID:austinvernsonger,项目名称:htmly,代码行数:29,代码来源:admin.php

示例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;
 }
开发者ID:joswilson,项目名称:NotJustOK,代码行数:15,代码来源:Security.class.php

示例6: needsRehash

 public function needsRehash($hash = null)
 {
     if (is_null($hash)) {
         $hash = $this->value;
     }
     return password_needs_rehash($hash, PASSWORD_BCRYPT, ['cost' => 10]);
 }
开发者ID:helmut,项目名称:forms,代码行数:7,代码来源:Password.php

示例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;
 }
开发者ID:Csardelacal,项目名称:PHPAuthServer,代码行数:26,代码来源:user.php

示例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'];
 }
开发者ID:eFiction,项目名称:v5_1-vaporware,代码行数:28,代码来源:auth.php

示例9: rehash

 public static function rehash($value)
 {
     if (password_needs_rehash($value, PASSWORD_BCRYPT)) {
         return password_hash($value, PASSWORD_BCRYPT);
     }
     return $value;
 }
开发者ID:taekunger,项目名称:kodekit,代码行数:7,代码来源:Hash.php

示例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;
 }
开发者ID:stevedien,项目名称:gatekeeper,代码行数:13,代码来源:SecurityQuestionModel.php

示例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');
     }
 }
开发者ID:borisper1,项目名称:vesi-cms-ng,代码行数:31,代码来源:User_handler.php

示例12: doesItNeedRehashing

 public static function doesItNeedRehashing($hash)
 {
     if (!is_string($hash)) {
         return false;
     }
     return password_needs_rehash($hash, PASSWORD_DEFAULT);
 }
开发者ID:educask,项目名称:EducaskCore,代码行数:7,代码来源:Hasher.php

示例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;
 }
开发者ID:farhanabbas1983,项目名称:ojs-1,代码行数:13,代码来源:Hashing.inc.php

示例14: needsNewHash

 public function needsNewHash()
 {
     if (password_needs_rehash($this->password, PASSWORD_DEFAULT)) {
         return true;
     }
     return false;
 }
开发者ID:anhnt4288,项目名称:owaspsecuritywithphp,代码行数:7,代码来源:PasswordCheck.php

示例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;
         }
     }
 }
开发者ID:yicheng340,项目名称:Econs-Forex-Game,代码行数:26,代码来源:PasswordAuthenticate.php


注:本文中的password_needs_rehash函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。