diff options
| author | Jacky Zhao <[email protected]> | 2020-05-11 20:08:51 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-05-11 20:08:51 -0700 |
| commit | 16bc33e7ac5298b2b3d72be32985dbab6d78db3f (patch) | |
| tree | 8ecea62dff7644ec3cc4bde30d711f9204bf0b92 /backend/hashing | |
| parent | Merge pull request #15 from jackyzha0/readme (diff) | |
| parent | Simplify hashing comparison (diff) | |
| download | ctrl-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')
| -rw-r--r-- | backend/hashing/hash.go | 9 |
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 |