From 119eced77afc256d4a2f31c6baea6d1214f377e9 Mon Sep 17 00:00:00 2001 From: alexferl Date: Mon, 9 Oct 2023 18:25:10 -0400 Subject: [PATCH] fix verify password --- util/password.go | 8 +++++++- util/password_test.go | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/util/password.go b/util/password.go index b348cbb..f2275a8 100644 --- a/util/password.go +++ b/util/password.go @@ -1,6 +1,8 @@ package util import ( + "errors" + "github.com/matthewhartstonge/argon2" ) @@ -15,10 +17,14 @@ func HashPassword(password []byte) (string, error) { } func VerifyPassword(password []byte, encoded []byte) error { - _, err := argon2.VerifyEncoded(encoded, password) + b, err := argon2.VerifyEncoded(encoded, password) if err != nil { return err } + if !b { + return errors.New("mismatch") + } + return nil } diff --git a/util/password_test.go b/util/password_test.go index 5f11415..ae29384 100644 --- a/util/password_test.go +++ b/util/password_test.go @@ -14,3 +14,12 @@ func TestPassword(t *testing.T) { err = VerifyPassword([]byte(enc), []byte(pwd)) assert.NoError(t, err) } + +func TestWrongPassword(t *testing.T) { + pwd := "s3cret" + enc, err := HashPassword([]byte(pwd)) + assert.NoError(t, err) + + err = VerifyPassword([]byte(enc), []byte("wrong")) + assert.Error(t, err) +}