From b9f5cfddc18c55eee62e1fb64a254fee9782c46c Mon Sep 17 00:00:00 2001 From: Yang Liu <50459973+ly4096x@users.noreply.github.com> Date: Sat, 22 Oct 2022 09:25:36 -0400 Subject: auth: enable authentication by token from password (#7198) Co-authored-by: Joe Chen --- internal/db/access_tokens.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'internal/db') diff --git a/internal/db/access_tokens.go b/internal/db/access_tokens.go index 7ed44ae9..58f77858 100644 --- a/internal/db/access_tokens.go +++ b/internal/db/access_tokens.go @@ -144,6 +144,11 @@ func (ErrAccessTokenNotExist) NotFound() bool { } func (db *accessTokens) GetBySHA1(ctx context.Context, sha1 string) (*AccessToken, error) { + // No need to waste a query for an empty SHA1. + if sha1 == "" { + return nil, ErrAccessTokenNotExist{args: errutil.Args{"sha": sha1}} + } + sha256 := cryptoutil.SHA256(sha1) token := new(AccessToken) err := db.WithContext(ctx).Where("sha256 = ?", sha256).First(token).Error -- cgit v1.2.3