diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-07-30 19:05:09 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-07-30 19:05:09 +0900 |
| commit | db0721e9820f399727b933088a276184e9565c9d (patch) | |
| tree | 4cde08ad2fc675bbbfbfab544738fd070293ea74 /backend/auth/auth.go | |
| parent | 61bf8dc35b82d0afd0263c0b6c37c2cfe5961a19 (diff) | |
| download | iosdc-japan-2024-albatross-db0721e9820f399727b933088a276184e9565c9d.tar.gz iosdc-japan-2024-albatross-db0721e9820f399727b933088a276184e9565c9d.tar.zst iosdc-japan-2024-albatross-db0721e9820f399727b933088a276184e9565c9d.zip | |
feat(backend): implement password-based authentication
Diffstat (limited to 'backend/auth/auth.go')
| -rw-r--r-- | backend/auth/auth.go | 12 |
1 files changed, 11 insertions, 1 deletions
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") |
