diff options
| author | Ryan Mehri <[email protected]> | 2020-05-11 20:41:16 -0600 |
|---|---|---|
| committer | Ryan Mehri <[email protected]> | 2020-05-11 20:41:16 -0600 |
| commit | d892cad72c1eb4ae20c1b7f1c5b9451650454c28 (patch) | |
| tree | 4563ceb597cda8339a6f49b4a3ff05c53fc67017 /backend/hashing | |
| parent | Merge pull request #15 from jackyzha0/readme (diff) | |
| download | ctrl-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.go | 13 |
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 |