feat: 密码强度校验增强,要求大写+小写+数字
- validatePassword 从"字母+数字"升级为"大写字母+小写字母+数字" - 拆分 pwLetter 为 pwLower([a-z]) 和 pwUpper([A-Z]) - 更新 ErrWeakPassword 错误提示 - 同步更新注册页和修改密码页的前端校验及提示文案
This commit is contained in:
@ -11,7 +11,8 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var pwLetter = regexp.MustCompile(`[a-zA-Z]`)
|
||||
var pwLower = regexp.MustCompile(`[a-z]`)
|
||||
var pwUpper = regexp.MustCompile(`[A-Z]`)
|
||||
var pwDigit = regexp.MustCompile(`\d`)
|
||||
|
||||
// dummyHash 防时序攻击:当用户不存在时,仍对虚拟哈希执行完整的 bcrypt 比对
|
||||
@ -25,9 +26,9 @@ func init() {
|
||||
dummyHash = hash
|
||||
}
|
||||
|
||||
// validatePassword 密码强度:至少 8 位 + 包含字母 + 包含数字
|
||||
// validatePassword 密码强度:至少 8 位 + 包含大写字母 + 包含小写字母 + 包含数字
|
||||
func validatePassword(pw string) error {
|
||||
if len(pw) < 8 || !pwLetter.MatchString(pw) || !pwDigit.MatchString(pw) {
|
||||
if len(pw) < 8 || !pwLower.MatchString(pw) || !pwUpper.MatchString(pw) || !pwDigit.MatchString(pw) {
|
||||
return common.ErrWeakPassword
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user