Add password changes

This commit is contained in:
maru committed 2024-04-28 17:27:58 -04:00
1 parent 4ce5a0198d
commit cbcc68f8e4
4 files changed
+59

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
package account
import (
"crypto/rand"
"fmt"
"github.com/pagefaultgames/pokerogue-server/db"
)
func ChangePW(uuid []byte, password string) error {
if len(password) < 6 {
return fmt.Errorf("invalid password")
}
salt := make([]byte, ArgonSaltSize)
_, err := rand.Read(salt)
if err != nil {
return fmt.Errorf(fmt.Sprintf("failed to generate salt: %s", err))
}
err = db.UpdateAccountPassword(uuid, deriveArgon2IDKey([]byte(password), salt), salt)
if err != nil {
return fmt.Errorf("failed to add account record: %s", err)
}
return nil
}