diff options
Diffstat (limited to 'pkg/service')
-rw-r--r-- | pkg/service/auth.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/pkg/service/auth.go b/pkg/service/auth.go index 30e574a..2fc06e3 100644 --- a/pkg/service/auth.go +++ b/pkg/service/auth.go @@ -21,6 +21,8 @@ type AuthController struct { key []byte } +var InvalidLogin = errors.New("Invalid login") + func NewAuthController( authRepository repository.AuthRepository, userRepository repository.UserRepository, @@ -35,17 +37,21 @@ func NewAuthController( func (c *AuthController) Login(ctx context.Context, username, password []byte) ([]byte, error) { id, err := c.authRepository.GetIDByUsername(ctx, string(username)) - if err != nil { + if errors.Is(err, repository.ErrRecordNotFound) { + return nil, InvalidLogin + } else if err != nil { return nil, err } hashedPassword, err := c.authRepository.GetPassword(ctx, id) - if err != nil { + if errors.Is(err, repository.ErrRecordNotFound) { + return nil, InvalidLogin + } else if err != nil { return nil, err } if err := bcrypt.CompareHashAndPassword(hashedPassword, password); err != nil { - return nil, err + return nil, InvalidLogin } token := &Token{ |