From b7c3e058e9b161065b9024458fc7be0b3c5e8cb5 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 10 Apr 2021 20:11:35 +0200 Subject: Implemented a user table and the CreateUser function --- pkg/database/password.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 pkg/database/password.go (limited to 'pkg/database/password.go') 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 +} -- cgit v1.2.3