aboutsummaryrefslogtreecommitdiff
path: root/pkg/database/password.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/database/password.go')
-rw-r--r--pkg/database/password.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/pkg/database/password.go b/pkg/database/password.go
new file mode 100644
index 0000000..d24183d
--- /dev/null
+++ b/pkg/database/password.go
@@ -0,0 +1,14 @@
+package database
+
+import "golang.org/x/crypto/bcrypt"
+
+// To allow for testing the error case (bad random is hard to trigger)
+var passwordFunction = bcrypt.GenerateFromPassword
+
+func hashPassword(password string) (string, error) {
+ bytes, err := passwordFunction([]byte(password), bcrypt.DefaultCost)
+ if err != nil {
+ return "", newPasswordError(err)
+ }
+ return string(bytes), nil
+}