aboutsummaryrefslogtreecommitdiff
path: root/backend/hashing/hash.go
diff options
context:
space:
mode:
authorJacky Zhao <[email protected]>2020-05-11 20:08:51 -0700
committerGitHub <[email protected]>2020-05-11 20:08:51 -0700
commit16bc33e7ac5298b2b3d72be32985dbab6d78db3f (patch)
tree8ecea62dff7644ec3cc4bde30d711f9204bf0b92 /backend/hashing/hash.go
parentMerge pull request #15 from jackyzha0/readme (diff)
parentSimplify hashing comparison (diff)
downloadctrl-v-16bc33e7ac5298b2b3d72be32985dbab6d78db3f.tar.xz
ctrl-v-16bc33e7ac5298b2b3d72be32985dbab6d78db3f.zip
Merge pull request #16 from jackyzha0/password
Add password check on post hash
Diffstat (limited to 'backend/hashing/hash.go')
-rw-r--r--backend/hashing/hash.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/backend/hashing/hash.go b/backend/hashing/hash.go
index 93a9cf9..e944fbe 100644
--- a/backend/hashing/hash.go
+++ b/backend/hashing/hash.go
@@ -29,4 +29,13 @@ func hashString(text string) string {
func HashPassword(password string) (string, error) {
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
return string(hashedPassword), err
+}
+
+func PasswordsEqual(dbPassword, parsedPassword string) bool {
+ dbPassBytes := []byte(dbPassword)
+ parsedPassBytes := []byte(parsedPassword)
+ compErr := bcrypt.CompareHashAndPassword(dbPassBytes, parsedPassBytes)
+
+ // if comparison error, the given password is not valid
+ return compErr == nil
} \ No newline at end of file