Skip to content

Commit

Permalink
fix verify password
Browse files Browse the repository at this point in the history
  • Loading branch information
alexferl committed Oct 9, 2023
1 parent fe10869 commit 119eced
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion util/password.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package util

import (
"errors"

"github.com/matthewhartstonge/argon2"
)

Expand All @@ -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
}
9 changes: 9 additions & 0 deletions util/password_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 119eced

Please sign in to comment.