aboutsummaryrefslogtreecommitdiff
path: root/src/user/secret.go
diff options
context:
space:
mode:
authorAlexander Kavon <me+git@alexkavon.com>2024-01-22 14:56:36 -0500
committerAlexander Kavon <me+git@alexkavon.com>2024-01-22 14:56:36 -0500
commita1df83e8b5737a198a3fba4de23ca2c80828f623 (patch)
tree95ae9bc9a87b945e149373d9753c8e158f003a6f /src/user/secret.go
parent4f15e271f541ecd525268efa40992e0f5c057e12 (diff)
added validation for user fields on sqlboiler.BeforeInsertHook, added hashing of secret before insert
Diffstat (limited to 'src/user/secret.go')
-rw-r--r--src/user/secret.go17
1 files changed, 4 insertions, 13 deletions
diff --git a/src/user/secret.go b/src/user/secret.go
index 55b8bc6..b6382fe 100644
--- a/src/user/secret.go
+++ b/src/user/secret.go
@@ -8,12 +8,7 @@ import (
"golang.org/x/crypto/argon2"
)
-type Secret struct {
- Raw string
- hash string
-}
-
-func (s Secret) HashSecret() error {
+func HashSecret(secret string) (string, error) {
hashconf := &struct {
memory uint32
iterations uint32
@@ -24,11 +19,11 @@ func (s Secret) HashSecret() error {
salt := make([]byte, hashconf.saltLength)
_, err := rand.Read(salt)
if err != nil {
- return err
+ return "", err
}
hash := argon2.IDKey(
- []byte(s.Raw),
+ []byte(secret),
salt,
hashconf.iterations,
hashconf.memory,
@@ -46,10 +41,6 @@ func (s Secret) HashSecret() error {
b64Salt,
b64Hash,
)
- s.hash = encodedHash
- return err
-}
-func (s *Secret) Hash() string {
- return s.hash
+ return encodedHash, nil
}