From db0721e9820f399727b933088a276184e9565c9d Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 30 Jul 2024 19:05:09 +0900 Subject: feat(backend): implement password-based authentication --- backend/auth/auth.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'backend/auth/auth.go') diff --git a/backend/auth/auth.go b/backend/auth/auth.go index 6b358c3..a8b9050 100644 --- a/backend/auth/auth.go +++ b/backend/auth/auth.go @@ -4,6 +4,8 @@ import ( "context" "fmt" + "golang.org/x/crypto/bcrypt" + "github.com/nsfisis/iosdc-2024-albatross/backend/db" ) @@ -12,7 +14,15 @@ func Login(ctx context.Context, queries *db.Queries, username, password string) if err != nil { return 0, err } - if userAuth.AuthType == "bypass" { + if userAuth.AuthType == "password" { + passwordHash := userAuth.PasswordHash + if passwordHash == nil { + panic("inconsistant data") + } + err := bcrypt.CompareHashAndPassword([]byte(*passwordHash), []byte(password)) + if err != nil { + return 0, err + } return int(userAuth.UserID), nil } return 0, fmt.Errorf("not implemented") -- cgit v1.2.3-70-g09d2