x3.5 登录验证问题
我想自己写个登录,然后是密码校验这步不太懂这些参数取自哪里:
在网上扒教程,定位到/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代码
functionget_passwordalgo() {
$algo = $this->base->settings['passwordalgo'];
if(empty($algo)) {
returnconstant('PASSWORD_BCRYPT');
} else {
returnconstant($algo) === null ? constant('PASSWORD_BCRYPT') : constant($algo);
}
}
functionget_passwordoptions() {
$options = $this->base->settings['passwordoptions'];
if(empty($options)) {
returnarray();
} else {
$result = json_decode($options, true);
returnis_array($result) ? $result : array();
}
}
functiongenerate_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;
}
functionverify_password($password, $hash, $salt = '') {
if(empty($salt)) {
returnpassword_verify($password, $hash);
} elseif(strlen($salt) == 6) {
returnhash_equals($hash, md5(md5($password).$salt));
} elseif(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);
}
returnfalse;
}
我知道答案 回答被采纳将会获得1 贡献 已有0人回答
在网上扒教程,定位到/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代码
functionget_passwordalgo() {
$algo = $this->base->settings['passwordalgo'];
if(empty($algo)) {
returnconstant('PASSWORD_BCRYPT');
} else {
returnconstant($algo) === null ? constant('PASSWORD_BCRYPT') : constant($algo);
}
}
functionget_passwordoptions() {
$options = $this->base->settings['passwordoptions'];
if(empty($options)) {
returnarray();
} else {
$result = json_decode($options, true);
returnis_array($result) ? $result : array();
}
}
functiongenerate_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;
}
functionverify_password($password, $hash, $salt = '') {
if(empty($salt)) {
returnpassword_verify($password, $hash);
} elseif(strlen($salt) == 6) {
returnhash_equals($hash, md5(md5($password).$salt));
} elseif(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);
}
returnfalse;
}
我知道答案 回答被采纳将会获得1 贡献 已有0人回答