summaryrefslogtreecommitdiff
path: root/auth/auth.go
diff options
context:
space:
mode:
Diffstat (limited to 'auth/auth.go')
-rw-r--r--auth/auth.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/auth/auth.go b/auth/auth.go
new file mode 100644
index 0000000..ac908ab
--- /dev/null
+++ b/auth/auth.go
@@ -0,0 +1,33 @@
+package auth
+
+import (
+ "golang.org/x/crypto/argon2"
+ "crypto/rand"
+ "sanine.net/git/phlox/config"
+)
+
+
+func GenerateSalt() ([]byte, error) {
+ salt := make([]byte, 10)
+ _, err := rand.Read(salt)
+ return salt, err
+}
+
+
+func HashPassword(password string, salt []byte) []byte {
+ return argon2.IDKey(
+ []byte(password), salt,
+ 1, 64*1024, 4, 32,
+ )
+}
+
+
+func AuthenticateUser(user config.User, password string) bool {
+ hash := HashPassword(password, user.Salt)
+ for i, v := range user.PasswordHash {
+ if v != hash[i] {
+ return false;
+ }
+ }
+ return true
+}