refactor(api): one password rule, one hash, one unique-violation check (#8002)
The length check and bcrypt call were copied into sign-up, reset, change and both admin paths; the unique-violation test into three api handlers and the library. checkNewPassword and hashPassword now sit in api/prelude.go, and db.IsUniqueViolation serves api and library. The taken-username and taken-email conflicts now carry a message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,8 +30,7 @@ func (h *handlers) handleChangePassword(w http.ResponseWriter, r *http.Request)
|
||||
writeErr(w, apierror.BadRequest("invalid_body", ""))
|
||||
return
|
||||
}
|
||||
if len(req.NewPassword) < minPasswordLength {
|
||||
writeErr(w, apierror.BadRequest("password_too_short", "password must be at least 8 chars"))
|
||||
if !checkNewPassword(w, req.NewPassword) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -47,7 +46,7 @@ func (h *handlers) handleChangePassword(w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(req.NewPassword), bcrypt.DefaultCost)
|
||||
hash, err := hashPassword(req.NewPassword)
|
||||
if err != nil {
|
||||
h.logger.Error("change password: hash failed", "err", err)
|
||||
writeErr(w, apierror.Internal(err))
|
||||
|
||||
Reference in New Issue
Block a user