2024-04-29 12:32:58 -07:00
|
|
|
// Copyright (C) 2024 Pagefault Games - All Rights Reserved
|
|
|
|
// https://github.com/pagefaultgames
|
|
|
|
|
2024-04-28 14:27:58 -07:00
|
|
|
package account
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/rand"
|
|
|
|
"fmt"
|
|
|
|
|
2024-04-29 12:22:27 -07:00
|
|
|
"github.com/pagefaultgames/rogueserver/db"
|
2024-04-28 14:27:58 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|