refactor: 修改验证码接口及登录接口
This commit is contained in:
@@ -32,4 +32,40 @@ if (!function_exists('password_with_salt')) {
|
||||
{
|
||||
return md5(hash('sha256', $password . $salt));
|
||||
}
|
||||
}
|
||||
|
||||
// 生成随机字符串
|
||||
if (!function_exists('random_str')) {
|
||||
/**
|
||||
* 生成随机字符串
|
||||
* @param $length integer 生成的长度
|
||||
* @param $type string 要生成的字符串类型(number, string, all)
|
||||
* @param $convert integer 大小写转换0为小写1为大写
|
||||
* @return string
|
||||
*/
|
||||
function random_str($length, $type = "string", $convert = "0")
|
||||
{
|
||||
$conf = [
|
||||
'number' => '0123456789',
|
||||
'string' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'all' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789='
|
||||
];
|
||||
$string = $conf[$type];
|
||||
if (!$string) {
|
||||
$string = $conf['string'];
|
||||
}
|
||||
$strlen = strlen($string) - 1;
|
||||
$char = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$char .= $string[mt_rand(0, $strlen)];
|
||||
}
|
||||
if ($convert > 0) {
|
||||
$res = strtoupper($char);
|
||||
} elseif ($convert == 0) {
|
||||
$res = $char;
|
||||
} elseif ($convert < 0) {
|
||||
$res = strtolower($char);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user