From 53f55ab8b0eceea32e58880c09785dd35943af0b Mon Sep 17 00:00:00 2001 From: Ryan Mehri Date: Mon, 11 May 2020 21:07:23 -0600 Subject: Simplify hashing comparison --- backend/cache/cache.go | 2 +- backend/hashing/hash.go | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) (limited to 'backend') diff --git a/backend/cache/cache.go b/backend/cache/cache.go index 918873e..56581b8 100644 --- a/backend/cache/cache.go +++ b/backend/cache/cache.go @@ -44,7 +44,7 @@ func (c *Cache) Get(hash, userPassword string) (db.Paste, error) { // if there is a password, check the provided one against it if p.Password != "" { // if passwords do not match, the user is unauthorized - if !hashing.ComparePasswords(p.Password, userPassword) { + if !hashing.PasswordsEqual(p.Password, userPassword) { return db.Paste{}, UserUnauthorized } } diff --git a/backend/hashing/hash.go b/backend/hashing/hash.go index d4b2566..e944fbe 100644 --- a/backend/hashing/hash.go +++ b/backend/hashing/hash.go @@ -31,15 +31,11 @@ func HashPassword(password string) (string, error) { return string(hashedPassword), err } -func ComparePasswords(dbPassword, parsedPassword string) bool { +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 - if compErr == nil { - return true - } else { - return false - } + return compErr == nil } \ No newline at end of file -- cgit v1.2.3