summary refs log tree commit diff stats
path: root/password/check.go
diff options
context:
space:
mode:
Diffstat (limited to 'password/check.go')
-rw-r--r--password/check.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/password/check.go b/password/check.go
new file mode 100644
index 0000000..b84e9fe
--- /dev/null
+++ b/password/check.go
@@ -0,0 +1,13 @@
+// Password package contains functions related to passwords.
+package password
+
+import "golang.org/x/crypto/bcrypt"
+
+// Check takes a string and hash as input and returns an error. If
+// the error is not nil then the consider the password wrong. We're
+// returning error instead of a bool so that we can print failed
+// logins to log and logging shouldn't happen here.
+func Check(password, hash string) error {
+	err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
+	return err
+}