summaryrefslogtreecommitdiff
path: root/auth/auth.go
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-05-14 20:12:06 -0500
committersanine <sanine.not@pm.me>2023-05-14 20:12:06 -0500
commit5b4251fd39c43e4cfed27e032a4efb2bbba28e38 (patch)
treef51840d5607eba0db9262045e330a1c8b8393449 /auth/auth.go
parent9571ccc4d87907067df98edeaa78f0c167fcff43 (diff)
add auth & pages
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
+}