aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacky Zhao <[email protected]>2020-05-12 08:04:27 -0700
committerGitHub <[email protected]>2020-05-12 08:04:27 -0700
commite9351959c2aa5666c8aea6bd18ccecdf95388e57 (patch)
treeb40ac4c4323756ae88eb57098372f3e00f4ff108
parentMerge pull request #16 from jackyzha0/password (diff)
parentclean up print (diff)
downloadctrl-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.go22
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