生成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, '旧密码不正确!');
}

相关文章:

  • 2021-06-08
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2021-10-06
猜你喜欢
  • 2022-02-14
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案