aboutsummaryrefslogtreecommitdiff
path: root/backend/hashing
diff options
context:
space:
mode:
authorRyan Mehri <[email protected]>2020-05-11 20:41:16 -0600
committerRyan Mehri <[email protected]>2020-05-11 20:41:16 -0600
commitd892cad72c1eb4ae20c1b7f1c5b9451650454c28 (patch)
tree4563ceb597cda8339a6f49b4a3ff05c53fc67017 /backend/hashing
parentMerge pull request #15 from jackyzha0/readme (diff)
downloadctrl-v-d892cad72c1eb4ae20c1b7f1c5b9451650454c28.tar.xz
ctrl-v-d892cad72c1eb4ae20c1b7f1c5b9451650454c28.zip
Add password check on post hash
Diffstat (limited to 'backend/hashing')
-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