feat: 密码强度校验/密码过期时间功能

This commit is contained in:
TsMask
2025-03-31 15:18:17 +08:00
parent 70c84e4950
commit 36aa32dc94
11 changed files with 293 additions and 40 deletions

View File

@@ -189,13 +189,19 @@ func (s *SysUserController) Add(c *gin.Context) {
c.JSON(400, resp.ErrMsg(msg))
return
}
if !regular.ValidPassword(body.Password) {
// msg := fmt.Sprintf("新增用户【%s】失败登录密码至少包含大小写字母、数字、特殊符号且不少于6位", body.UserName)
msg := fmt.Sprintf("New user [%s] failed, the login password contains at least upper and lower case letters, numbers, special symbols, and not less than 6 bits", body.UserName)
c.JSON(400, resp.ErrMsg(msg))
// if !regular.ValidPassword(body.Password) {
// // msg := fmt.Sprintf("新增用户【%s】失败登录密码至少包含大小写字母、数字、特殊符号且不少于6位", body.UserName)
// msg := fmt.Sprintf("New user [%s] failed, the login password contains at least upper and lower case letters, numbers, special symbols, and not less than 6 bits", body.UserName)
// c.JSON(400, resp.ErrMsg(msg))
// return
// }
// 检查用户密码策略强度
ok, errMsg := s.sysUserService.ValidatePasswordPolicy(body.Password, language)
if !ok {
c.JSON(200, resp.ErrMsg(errMsg))
return
}
// 检查用户登录账号是否唯一
uniqueUserName := s.sysUserService.CheckUniqueByUserName(body.UserName, 0)
if !uniqueUserName {
@@ -431,11 +437,17 @@ func (s *SysUserController) Password(c *gin.Context) {
return
}
if !regular.ValidPassword(body.Password) {
c.JSON(200, resp.ErrMsg("Login password contains at least upper and lower case letters, numbers, special symbols, and not less than 6 digits"))
// if !regular.ValidPassword(body.Password) {
// c.JSON(200, resp.ErrMsg("Login password contains at least upper and lower case letters, numbers, special symbols, and not less than 6 digits"))
// return
// }
// 检查用户密码策略强度
ok, errMsg := s.sysUserService.ValidatePasswordPolicy(body.Password, language)
if !ok {
c.JSON(200, resp.ErrMsg(errMsg))
return
}
// 检查是否存在
userInfo := s.sysUserService.FindById(body.UserId)
if userInfo.UserId != body.UserId {