diff options
| author | Ryan Mehri <[email protected]> | 2020-05-11 23:02:02 -0600 |
|---|---|---|
| committer | Ryan Mehri <[email protected]> | 2020-05-11 23:02:02 -0600 |
| commit | 8789074ecdaeecdd721a5fa2a4e32840f6231d44 (patch) | |
| tree | 58f4c06116a73be078186a9b46e986e430106b72 | |
| parent | Simplify hashing comparison (diff) | |
| download | ctrl-v-8789074ecdaeecdd721a5fa2a4e32840f6231d44.tar.xz ctrl-v-8789074ecdaeecdd721a5fa2a4e32840f6231d44.zip | |
fix issue with empty password being hashed
| -rw-r--r-- | backend/cache/cache.go | 1 | ||||
| -rw-r--r-- | backend/db/db.go | 22 |
2 files changed, 13 insertions, 10 deletions
diff --git a/backend/cache/cache.go b/backend/cache/cache.go index 56581b8..f999d86 100644 --- a/backend/cache/cache.go +++ b/backend/cache/cache.go @@ -42,6 +42,7 @@ func (c *Cache) Get(hash, userPassword string) (db.Paste, error) { } // if there is a password, check the provided one against it + println(p.Password) if p.Password != "" { // if passwords do not match, the user is unauthorized if !hashing.PasswordsEqual(p.Password, userPassword) { diff --git a/backend/db/db.go b/backend/db/db.go index 9bfe55a..fba7bd9 100644 --- a/backend/db/db.go +++ b/backend/db/db.go @@ -38,18 +38,20 @@ func New(ip, content, expiry, title, password string) (string, error) { return "", errs } - // hash given password - hashedPass, err := hashing.HashPassword(password) - if err != nil { - return "", fmt.Errorf("could not hash password: %s", err.Error()) - } - // create new struct new := Paste{ - Hash: hash, - Content: content, - Title: title, - Password: hashedPass, + Hash: hash, + Content: content, + Title: title, + } + + if password != "" { + // hash given password + hashedPass, err := hashing.HashPassword(password) + if err != nil { + return "", fmt.Errorf("could not hash password: %s", err.Error()) + } + new.Password = hashedPass } // check if expiry |