feat(auth): lab7 upgrade legacy Argon2id hashes after successful login
This commit is contained in:
@@ -57,3 +57,17 @@ func (r *UserRepo) GetByUsername(ctx context.Context, username string) (*domain.
|
||||
}
|
||||
return nil, &domain.NotFoundError{Entity: "user", ID: username}
|
||||
}
|
||||
|
||||
func (r *UserRepo) ReplacePasswordHash(ctx context.Context, id, previous, next string) (bool, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
u := r.users[id]
|
||||
if u == nil || u.PasswordHash != previous {
|
||||
return false, nil
|
||||
}
|
||||
u.PasswordHash = next
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@@ -73,4 +73,12 @@ func (r *UserRepo) GetByUsername(ctx context.Context, username string) (*domain.
|
||||
return u, nil
|
||||
}
|
||||
|
||||
func (r *UserRepo) ReplacePasswordHash(ctx context.Context, id, previous, next string) (bool, error) {
|
||||
result, err := r.pool.Exec(ctx, "UPDATE users SET password_hash=$3 WHERE id=$1::uuid AND password_hash=$2", id, previous, next)
|
||||
if err != nil {
|
||||
return false, mapError(err)
|
||||
}
|
||||
return result.RowsAffected() == 1, nil
|
||||
}
|
||||
|
||||
var _ domain.UserRepository = (*UserRepo)(nil)
|
||||
|
||||
Reference in New Issue
Block a user