aboutsummaryrefslogtreecommitdiff
path: root/backend/hashing/hash.go
diff options
context:
space:
mode:
Diffstat (limited to 'backend/hashing/hash.go')
-rw-r--r--backend/hashing/hash.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/backend/hashing/hash.go b/backend/hashing/hash.go
index 93a9cf9..d8e699a 100644
--- a/backend/hashing/hash.go
+++ b/backend/hashing/hash.go
@@ -29,4 +29,17 @@ func hashString(text string) string {
func HashPassword(password string) (string, error) {
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
return string(hashedPassword), err
+}
+
+func ComparePasswords(dbPassword, gotPassword string) bool {
+ dbPassBytes := []byte(dbPassword)
+ gotPassBytes := []byte(gotPassword)
+ compErr := bcrypt.CompareHashAndPassword(dbPassBytes, gotPassBytes)
+
+ // if comparison error, the given password is not valid
+ if compErr != nil {
+ return false
+ } else {
+ return true
+ }
} \ No newline at end of file