密码加salt

生成salt

$salt = Strings::randomstr(6);
/**
 * 生成随机字符串
 *
 * @param  string  $lenth  长度
 * @return string 字符串
 */
public static function randomstr($lenth = 6)
{
    return self::random($lenth, '123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ');
}

生成salt密码

/**
 * 加密密码。
 * 
 * @param  string  $password  密码明文。
 * @param  string  $salt      密码加密盐。
 * @return string
 */
public static function encryptPassword($password, $salt)
{
    return md5(md5($password) . $salt);
}

存储salt+密码

$data = [
    'password'      => $encryptPassword,
    'u_by'        => $adminId,
    'password_salt' => $salt
];

比对密码是否正确

$oldPwdEncrypt = Auth::encryptPassword($oldPwd, $adminInfo['password_salt']);
if ($oldPwdEncrypt != $adminInfo['password']) {
    Core::exception(STATUS_SERVER_ERROR, '旧密码不正确!');
}

猜你喜欢

转载自www.cnblogs.com/jiqing9006/p/12155041.html
今日推荐