From c6fa875148c183ed0bfc4df237f73588a227da1e Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 11 Oct 2023 11:55:44 +0800 Subject: [PATCH] email limit & password limit --- server/auth/internal/logic/useremailregisterlogic.go | 4 ++++ server/auth/internal/logic/userregisterlogic.go | 4 ++++ server/auth/internal/logic/userresetpasswordlogic.go | 4 ++++ utils/auth/register.go | 2 +- utils/basic/basic.go | 1 + 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/server/auth/internal/logic/useremailregisterlogic.go b/server/auth/internal/logic/useremailregisterlogic.go index 60e66a2c..edc2d10c 100644 --- a/server/auth/internal/logic/useremailregisterlogic.go +++ b/server/auth/internal/logic/useremailregisterlogic.go @@ -47,6 +47,10 @@ func (l *UserEmailRegisterLogic) UserEmailRegister(req *types.RequestEmailRegist return resp.SetStatus(basic.CodeOAuthEmailErr) } + if len(req.Email) > 50 { + return resp.SetStatusWithMessage(basic.CodeOAuthEmailErr, "email len must < 50") + } + if !TimeLimit.Is(req.Email) { return resp.SetStatus(basic.CodeEmailTimeShortErr) } diff --git a/server/auth/internal/logic/userregisterlogic.go b/server/auth/internal/logic/userregisterlogic.go index d9ed3fa3..45f0d73c 100644 --- a/server/auth/internal/logic/userregisterlogic.go +++ b/server/auth/internal/logic/userregisterlogic.go @@ -41,6 +41,10 @@ func (l *UserRegisterLogic) UserRegister(req *types.RequestUserRegister, userinf return resp.SetStatus(basic.CodeOAuthEmailErr) } + if len(req.Email) > 50 { + return resp.SetStatusWithMessage(basic.CodeOAuthEmailErr, "email len must < 50") + } + // _, err := l.svcCtx.AllModels.FsUser.FindUserByEmail(l.ctx, req.Email) // if err == nil { // return resp.SetStatus(basic.CodeEmailExistsErr) diff --git a/server/auth/internal/logic/userresetpasswordlogic.go b/server/auth/internal/logic/userresetpasswordlogic.go index aa9ab591..cc7a55a2 100644 --- a/server/auth/internal/logic/userresetpasswordlogic.go +++ b/server/auth/internal/logic/userresetpasswordlogic.go @@ -39,6 +39,10 @@ func (l *UserResetPasswordLogic) UserResetPassword(req *types.RequestUserResetPa // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) // userinfo 传入值时, 一定不为null + if len(req.NewPassword) > 30 { + return resp.SetStatusWithMessage(basic.CodePasswordErr, "password len must < 30") + } + rt, err := l.svcCtx.ResetTokenManger.Decrypt(req.ResetToken) // ResetToken if err != nil { logx.Error(err) diff --git a/utils/auth/register.go b/utils/auth/register.go index dec96fb2..3531a3be 100644 --- a/utils/auth/register.go +++ b/utils/auth/register.go @@ -118,7 +118,7 @@ func ValidateEmail(email string) bool { // ValidatePassword checks if the provided password is strong enough. // In this example, we just check if the password length is 8 or more. func ValidatePassword(password string) bool { - const minPasswordLength = 8 + const minPasswordLength = 30 return len(password) >= minPasswordLength } diff --git a/utils/basic/basic.go b/utils/basic/basic.go index 8ce30032..3621d6bb 100644 --- a/utils/basic/basic.go +++ b/utils/basic/basic.go @@ -58,6 +58,7 @@ var ( CodeEmailExistsErr = &StatusResponse{5053, "email exists"} // email存在 CodeEmailTimeShortErr = &StatusResponse{5053, "email with the time of resend is too short"} // email重发的时间太短 CodeResetPasswordErr = &StatusResponse{5054, "reset password error"} // 无效密码 + CodeEmailErr = &StatusResponse{5054, "email error"} CodeSafeValueRangeErr = &StatusResponse{5040, "value not in range"} // 值不在范围内 CodeTemplateErr = &StatusResponse{5040, "template parsed error"} // 模板解析错误