chore: finalize lab7 security verification
CI / verify (pull_request) Successful in 14m53s

This commit is contained in:
2026-11-06 22:00:42 +03:00
parent 5ac64f51fa
commit a8edaf058d
53 changed files with 1130 additions and 224 deletions
+5 -5
View File
@@ -37,7 +37,7 @@ func (s *Server) createSession(w http.ResponseWriter, r *http.Request) *apiError
credentials, err := s.userRepository.UserByUsername(r.Context(), username)
if errors.Is(err, model.ErrNotFound) {
if _, verifyErr := s.passwords.Verify(passwordValue, s.passwords.DummyHash()); verifyErr != nil {
return internalError()
return passwordOperationError(verifyErr)
}
return unauthorized()
}
@@ -46,7 +46,7 @@ func (s *Server) createSession(w http.ResponseWriter, r *http.Request) *apiError
}
verified, err := s.passwords.Verify(passwordValue, credentials.PasswordHash)
if err != nil {
return internalError()
return passwordOperationError(err)
}
if !verified {
return unauthorized()
@@ -70,14 +70,14 @@ func (s *Server) createSession(w http.ResponseWriter, r *http.Request) *apiError
func (s *Server) rehashPassword(ctx context.Context, credentials model.UserCredentials, passwordValue string) *apiError {
needsRehash, err := s.passwords.NeedsRehash(credentials.PasswordHash)
if err != nil {
return internalError()
return passwordOperationError(err)
}
if !needsRehash {
return nil
}
passwordHash, err := s.passwords.Hash(passwordValue)
if err != nil {
return internalError()
return passwordOperationError(err)
}
updated, err := s.userRepository.UpdatePasswordHash(ctx, credentials.ID, credentials.PasswordHash, passwordHash)
if err != nil {
@@ -95,7 +95,7 @@ func (s *Server) rehashPassword(ctx context.Context, credentials model.UserCrede
}
verified, err := s.passwords.Verify(passwordValue, current.PasswordHash)
if err != nil {
return internalError()
return passwordOperationError(err)
}
if !verified {
return unauthorized()