aboutsummaryrefslogtreecommitdiff
path: root/pkg/database/password.go
diff options
context:
space:
mode:
authorJulien Dessaux2021-04-10 20:11:35 +0200
committerJulien Dessaux2021-04-12 11:11:38 +0200
commitb7c3e058e9b161065b9024458fc7be0b3c5e8cb5 (patch)
treed8a5d047f2aaabb7118a86123cd61761aa4bda6a /pkg/database/password.go
parentBegan implementing a database backend (diff)
downloadtrains-b7c3e058e9b161065b9024458fc7be0b3c5e8cb5.tar.gz
trains-b7c3e058e9b161065b9024458fc7be0b3c5e8cb5.tar.bz2
trains-b7c3e058e9b161065b9024458fc7be0b3c5e8cb5.zip
Implemented a user table and the CreateUser function
Diffstat (limited to '')
-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
+}