diff options
| author | Jacky Zhao <[email protected]> | 2020-05-12 08:04:27 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-05-12 08:04:27 -0700 |
| commit | e9351959c2aa5666c8aea6bd18ccecdf95388e57 (patch) | |
| tree | b40ac4c4323756ae88eb57098372f3e00f4ff108 | |
| parent | Merge pull request #16 from jackyzha0/password (diff) | |
| parent | clean up print (diff) | |
| download | ctrl-v-e9351959c2aa5666c8aea6bd18ccecdf95388e57.tar.xz ctrl-v-e9351959c2aa5666c8aea6bd18ccecdf95388e57.zip | |
Merge pull request #17 from jackyzha0/password
Fix empty password being hashed
| -rw-r--r-- | backend/db/db.go | 22 |
1 files changed, 12 insertions, 10 deletions
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 |