|
我想自己寫個登錄,然后是密碼校驗這步不太懂這些參數取自哪里:
在網上扒教程,定位到/uc_client/user.php,約365行的這幾個方法(最底部):
這里有幾個疑問,在pre_ucenter_members的salt字段為空字符串時,應該走的分支:password_verify($password, $hash);
隨后兩個參數$algo和$options我沒看懂,雖然我用返回的是true,但是這里沒有和數據庫的密碼作比對,也可以判斷嗎?
$password = '123456'
constant('PASSWORD_BCRYPT') = '2y'
$hash = password_hash($password, constant('PASSWORD_BCRYPT'), array());
$pass = password_verify($password, $hash);
var_dump($pass);
user.php代碼
function get_passwordalgo() {
$algo = $this->base->settings['passwordalgo'];
if(empty($algo)) {
return constant('PASSWORD_BCRYPT');
} else {
return constant($algo) === null ? constant('PASSWORD_BCRYPT') : constant($algo);
}
}
function get_passwordoptions() {
$options = $this->base->settings['passwordoptions'];
if(empty($options)) {
return array();
} else {
$result = json_decode($options, true);
return is_array($result) ? $result : array();
}
}
function generate_password($password) {
$algo = $this->get_passwordalgo();
$options = $this->get_passwordoptions();
$hash = password_hash($password, $algo, $options);
return ($hash === false || $hash === null || !password_verify($password, $hash)) ? password_hash($password, PASSWORD_BCRYPT) : $hash;
}
function verify_password($password, $hash, $salt = '') {
if(empty($salt)) {
return password_verify($password, $hash);
} else if(strlen($salt) == 6) {
return hash_equals($hash, md5(md5($password).$salt));
} else if(strlen($salt) > 6 && strlen($salt) < 20 && file_exists(UC_ROOT . "lib/uc_password_$salt.class.php")) {
$classname = "uc_password_$salt";
include(UC_ROOT . "lib/uc_password_$salt.class.php");
return $classname::verify_password($password, $hash);
}
return false;
}
我知道答案
回答被采納將會獲得 1 貢獻 已有0人回答
|
|