新增密码策略
This commit is contained in:
parent
64d606013d
commit
75ac1e9770
@ -24,7 +24,7 @@ class SystemController extends AbstractController
|
|||||||
*
|
*
|
||||||
* @apiParam {String} type
|
* @apiParam {String} type
|
||||||
* - get: 获取(默认)
|
* - get: 获取(默认)
|
||||||
* - save: 保存设置(参数:reg、login_code)
|
* - save: 保存设置(参数:reg、login_code、password_policy)
|
||||||
|
|
||||||
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||||
@ -40,7 +40,7 @@ class SystemController extends AbstractController
|
|||||||
User::auth('admin');
|
User::auth('admin');
|
||||||
$all = Request::input();
|
$all = Request::input();
|
||||||
foreach ($all AS $key => $value) {
|
foreach ($all AS $key => $value) {
|
||||||
if (!in_array($key, ['reg', 'login_code'])) {
|
if (!in_array($key, ['reg', 'login_code', 'password_policy'])) {
|
||||||
unset($all[$key]);
|
unset($all[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,6 +51,7 @@ class SystemController extends AbstractController
|
|||||||
//
|
//
|
||||||
$setting['reg'] = $setting['reg'] ?: 'open';
|
$setting['reg'] = $setting['reg'] ?: 'open';
|
||||||
$setting['login_code'] = $setting['login_code'] ?: 'auto';
|
$setting['login_code'] = $setting['login_code'] ?: 'auto';
|
||||||
|
$setting['password_policy'] = $setting['password_policy'] ?: 'simple';
|
||||||
//
|
//
|
||||||
return Base::retSuccess('success', $setting ?: json_decode('{}'));
|
return Base::retSuccess('success', $setting ?: json_decode('{}'));
|
||||||
}
|
}
|
||||||
|
@ -272,14 +272,10 @@ class UsersController extends AbstractController
|
|||||||
//
|
//
|
||||||
$oldpass = trim(Request::input('oldpass'));
|
$oldpass = trim(Request::input('oldpass'));
|
||||||
$newpass = trim(Request::input('newpass'));
|
$newpass = trim(Request::input('newpass'));
|
||||||
if (strlen($newpass) < 6) {
|
|
||||||
return Base::retError('密码设置不能小于6位数');
|
|
||||||
} elseif (strlen($newpass) > 32) {
|
|
||||||
return Base::retError('密码最多只能设置32位数');
|
|
||||||
}
|
|
||||||
if ($oldpass == $newpass) {
|
if ($oldpass == $newpass) {
|
||||||
return Base::retError('新旧密码一致');
|
return Base::retError('新旧密码一致');
|
||||||
}
|
}
|
||||||
|
User::passwordPolicy($newpass);
|
||||||
//
|
//
|
||||||
$verify = User::whereUserid($user->userid)->wherePassword(Base::md52($oldpass, User::token2encrypt()))->count();
|
$verify = User::whereUserid($user->userid)->wherePassword(Base::md52($oldpass, User::token2encrypt()))->count();
|
||||||
if (empty($verify)) {
|
if (empty($verify)) {
|
||||||
@ -487,11 +483,7 @@ class UsersController extends AbstractController
|
|||||||
// 密码
|
// 密码
|
||||||
if (Arr::exists($data, 'password')) {
|
if (Arr::exists($data, 'password')) {
|
||||||
$password = trim($data['password']);
|
$password = trim($data['password']);
|
||||||
if (strlen($password) < 6) {
|
User::passwordPolicy($password);
|
||||||
return Base::retError('密码设置不能小于6位数');
|
|
||||||
} elseif (strlen($password) > 32) {
|
|
||||||
return Base::retError('密码最多只能设置32位数');
|
|
||||||
}
|
|
||||||
$upArray['encrypt'] = Base::generatePassword(6);
|
$upArray['encrypt'] = Base::generatePassword(6);
|
||||||
$upArray['password'] = Base::md52($password, $upArray['encrypt']);
|
$upArray['password'] = Base::md52($password, $upArray['encrypt']);
|
||||||
$upArray['changepass'] = 1;
|
$upArray['changepass'] = 1;
|
||||||
|
@ -185,11 +185,7 @@ class User extends AbstractModel
|
|||||||
throw new ApiException('邮箱地址已存在');
|
throw new ApiException('邮箱地址已存在');
|
||||||
}
|
}
|
||||||
//密码
|
//密码
|
||||||
if (strlen($password) < 6) {
|
self::passwordPolicy($password);
|
||||||
throw new ApiException('密码设置不能小于6位数');
|
|
||||||
} elseif (strlen($password) > 32) {
|
|
||||||
throw new ApiException('密码最多只能设置32位数');
|
|
||||||
}
|
|
||||||
//开始注册
|
//开始注册
|
||||||
$encrypt = Base::generatePassword(6);
|
$encrypt = Base::generatePassword(6);
|
||||||
$inArray = [
|
$inArray = [
|
||||||
@ -459,4 +455,35 @@ class User extends AbstractModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测密码策略是否符合
|
||||||
|
* @param $password
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function passwordPolicy($password)
|
||||||
|
{
|
||||||
|
if (strlen($password) < 6) {
|
||||||
|
throw new ApiException('密码设置不能小于6位数');
|
||||||
|
}
|
||||||
|
if (strlen($password) > 32) {
|
||||||
|
throw new ApiException('密码最多只能设置32位数');
|
||||||
|
}
|
||||||
|
// 复杂密码
|
||||||
|
$password_policy = Base::settingFind('system', 'password_policy');
|
||||||
|
if ($password_policy == 'complex') {
|
||||||
|
if (preg_match("/^[0-9]+$/", $password)) {
|
||||||
|
throw new ApiException('密码不能全是数字,请包含数字,字母大小写或者特殊字符');
|
||||||
|
}
|
||||||
|
if (preg_match("/^[a-zA-Z]+$/", $password)) {
|
||||||
|
throw new ApiException('密码不能全是字母,请包含数字,字母大小写或者特殊字符');
|
||||||
|
}
|
||||||
|
if (preg_match("/^[0-9A-Z]+$/", $password)) {
|
||||||
|
throw new ApiException('密码不能全是数字+大写字母,密码包含数字,字母大小写或者特殊字符');
|
||||||
|
}
|
||||||
|
if (preg_match("/^[0-9a-z]+$/", $password)) {
|
||||||
|
throw new ApiException('密码不能全是数字+小写字母,密码包含数字,字母大小写或者特殊字符');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,7 +323,7 @@ export default {
|
|||||||
that.getLists();
|
that.getLists();
|
||||||
resolve()
|
resolve()
|
||||||
}).catch(({msg}) => {
|
}).catch(({msg}) => {
|
||||||
$A.modalError(msg);
|
$A.modalError(msg, 301);
|
||||||
that.loadIng--;
|
that.loadIng--;
|
||||||
that.getLists();
|
that.getLists();
|
||||||
resolve()
|
resolve()
|
||||||
|
@ -14,6 +14,14 @@
|
|||||||
<Radio label="close">{{$L('关闭')}}</Radio>
|
<Radio label="close">{{$L('关闭')}}</Radio>
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
<FormItem :label="$L('密码策略')" prop="passwordPolicy">
|
||||||
|
<RadioGroup v-model="formDatum.password_policy">
|
||||||
|
<Radio label="simple">{{$L('简单')}}</Radio>
|
||||||
|
<Radio label="complex">{{$L('复杂')}}</Radio>
|
||||||
|
</RadioGroup>
|
||||||
|
<div v-if="formDatum.password_policy == 'simple'" class="form-tip">{{$L('简单:大于或等于6个字符。')}}</div>
|
||||||
|
<div v-else-if="formDatum.password_policy == 'complex'" class="form-tip">{{$L('复杂:大于或等于6个字符,包含数字、字母大小写或者特殊字符。')}}</div>
|
||||||
|
</FormItem>
|
||||||
</Form>
|
</Form>
|
||||||
<div class="setting-footer">
|
<div class="setting-footer">
|
||||||
<Button :loading="loadIng > 0" type="primary" @click="submitForm">{{$L('提交')}}</Button>
|
<Button :loading="loadIng > 0" type="primary" @click="submitForm">{{$L('提交')}}</Button>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user