aboutsummaryrefslogtreecommitdiffstats
path: root/internal/auth/password.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/auth/password.go')
-rw-r--r--internal/auth/password.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/internal/auth/password.go b/internal/auth/password.go
new file mode 100644
index 0000000..97aba55
--- /dev/null
+++ b/internal/auth/password.go
@@ -0,0 +1,13 @@
+// Package auth implements password hashing, JWT sessions and CSRF tokens.
+package auth
+
+import "golang.org/x/crypto/bcrypt"
+
+func HashPassword(pw string) (string, error) {
+ h, err := bcrypt.GenerateFromPassword([]byte(pw), bcrypt.DefaultCost)
+ return string(h), err
+}
+
+func CheckPassword(hash, pw string) bool {
+ return bcrypt.CompareHashAndPassword([]byte(hash), []byte(pw)) == nil
+}