first commit
This commit is contained in:
108
app/api/validate/LoginAccountValidate.php
Normal file
108
app/api/validate/LoginAccountValidate.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
use app\common\cache\UserAccountSafeCache;
|
||||
use app\common\enum\LoginEnum;
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\enum\user\UserTerminalEnum;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\sms\SmsDriver;
|
||||
use app\common\validate\BaseValidate;
|
||||
use app\common\model\user\User;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 账号密码登录校验
|
||||
* Class LoginValidate
|
||||
* @package app\api\validate
|
||||
*/
|
||||
class LoginAccountValidate extends BaseValidate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'terminal' => 'require|in:' . UserTerminalEnum::WECHAT_MMP . ',' . UserTerminalEnum::WECHAT_OA . ','
|
||||
. UserTerminalEnum::H5 . ',' . UserTerminalEnum::PC . ',' . UserTerminalEnum::IOS .
|
||||
',' . UserTerminalEnum::ANDROID,
|
||||
'account' => 'require',
|
||||
'password' => 'require|checkPassword',
|
||||
];
|
||||
|
||||
|
||||
protected $message = [
|
||||
'terminal.require' => 'network.parameterAbnormality',//终端参数缺失
|
||||
'terminal.in' => 'network.parameterAbnormality',//终端参数状态值不正确
|
||||
'account.require' => 'network.parameterAbnormality',//请输入账号
|
||||
'password.require' => 'network.parameterAbnormality',//请输入密码
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 登录密码校验
|
||||
* @param $password
|
||||
* @param $other
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2022/9/15 14:39
|
||||
*/
|
||||
public function checkPassword($password, $other, $data)
|
||||
{
|
||||
//账号安全机制,连续输错后锁定,防止账号密码暴力破解
|
||||
$userAccountSafeCache = new UserAccountSafeCache();
|
||||
if (!$userAccountSafeCache->isSafe()) {
|
||||
return 'network.pwdErrorLimit';
|
||||
//密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试
|
||||
}
|
||||
|
||||
$where = [];
|
||||
|
||||
$login_way = $data['login_way'];//0邮箱1手机号
|
||||
if($login_way == 1){
|
||||
$where = ['country_code' => $data['country_code']];
|
||||
}
|
||||
|
||||
$userInfo = User::where($where)
|
||||
->where(['account' => $data['account']])
|
||||
->field(['password,is_disable,is_open'])
|
||||
->findOrEmpty();
|
||||
|
||||
if ($userInfo->isEmpty()) {
|
||||
$userAccountSafeCache->record();
|
||||
return 'login.accountNoExist';//用户不存在
|
||||
}
|
||||
|
||||
if ($userInfo['is_open'] === YesNoEnum::NO) {
|
||||
$userAccountSafeCache->record();
|
||||
return 'login.accountNoExist';//用户未启用
|
||||
}
|
||||
|
||||
if ($userInfo['is_disable'] === YesNoEnum::YES) {
|
||||
$userAccountSafeCache->record();
|
||||
return 'login.accountLocked';//用户已禁用
|
||||
}
|
||||
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
if ($userInfo['password'] !== create_password($password, $passwordSalt)) {
|
||||
$userAccountSafeCache->record();
|
||||
return 'login.passwordError';//密码错误
|
||||
}
|
||||
|
||||
$userAccountSafeCache->relieve();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user