21 lines
580 B
PHP
21 lines
580 B
PHP
/**
|
||
* 密码哈希函数(使用 bcrypt,兼容旧版 MD5)
|
||
* @deprecated 请使用 app\models\Employee::hashPassword()
|
||
*/
|
||
function md5_pwd($pwd) {
|
||
return password_hash($pwd, PASSWORD_BCRYPT, ['cost' => 12]);
|
||
}
|
||
|
||
/**
|
||
* 验证密码(兼容旧版 MD5)
|
||
* @deprecated 请使用 app\models\Employee::validateLogin()
|
||
*/
|
||
function verify_pwd($pwd, $hash) {
|
||
// 判断是否为 bcrypt(bcrypt 哈希以 $2y$ 开头)
|
||
if (substr($hash, 0, 4) === '$2y$') {
|
||
return password_verify($pwd, $hash);
|
||
}
|
||
// 兼容旧版 MD5
|
||
return md5($pwd) === $hash;
|
||
}
|