mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(http): improve invalid login handling (#597)
* feat(http): improve invalid login handling * fix(http): do not log password
This commit is contained in:
parent
9c16c7a4a1
commit
6b1490726f
2 changed files with 3 additions and 3 deletions
|
@ -43,7 +43,7 @@ func (s *service) Login(ctx context.Context, username, password string) (*domain
|
||||||
u, err := s.userSvc.FindByUsername(ctx, username)
|
u, err := s.userSvc.FindByUsername(ctx, username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log.Error().Err(err).Msgf("could not find user by username: %v", username)
|
s.log.Error().Err(err).Msgf("could not find user by username: %v", username)
|
||||||
return nil, err
|
return nil, errors.Wrapf(err, "invalid login: %s", username)
|
||||||
}
|
}
|
||||||
|
|
||||||
if u == nil {
|
if u == nil {
|
||||||
|
@ -58,7 +58,7 @@ func (s *service) Login(ctx context.Context, username, password string) (*domain
|
||||||
|
|
||||||
if !match {
|
if !match {
|
||||||
s.log.Error().Msg("bad credentials")
|
s.log.Error().Msg("bad credentials")
|
||||||
return nil, errors.New("bad credentials")
|
return nil, errors.Errorf("invalid login: %s", username)
|
||||||
}
|
}
|
||||||
|
|
||||||
return u, nil
|
return u, nil
|
||||||
|
|
|
@ -75,7 +75,7 @@ func (h authHandler) login(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
_, err := h.service.Login(ctx, data.Username, data.Password)
|
_, err := h.service.Login(ctx, data.Username, data.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.log.Error().Err(err).Msgf("invalid login [%s] from: %s", ReadUserIP(r))
|
h.log.Error().Err(err).Msgf("Auth: Failed login attempt username: [%s] ip: %s", data.Username, ReadUserIP(r))
|
||||||
h.encoder.StatusResponse(ctx, w, nil, http.StatusUnauthorized)
|
h.encoder.StatusResponse(ctx, w, nil, http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue