feat: add administration domain core
This commit is contained in:
1 parent
065dcd955a
commit
cea2751dc5
9 files changed
+1135
No files matched your search
@@ -0,0 +1,29 @@
|
||||
package administration
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"golang.org/x/crypto/scrypt"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var phonePattern = regexp.MustCompile(`^\+?[0-9]{6,20}$`)
|
||||
|
||||
func NormalizePhone(value string) string {
|
||||
r := strings.NewReplacer(" ", "", "\t", "", "\n", "", "\r", "", "(", "", ")", "", "-", "")
|
||||
return r.Replace(strings.TrimSpace(value))
|
||||
}
|
||||
func ValidPhone(value string) bool { return phonePattern.MatchString(NormalizePhone(value)) }
|
||||
func HashPassword(password string) (PasswordHash, error) {
|
||||
salt := make([]byte, 16)
|
||||
if _, err := rand.Read(salt); err != nil {
|
||||
return PasswordHash{}, err
|
||||
}
|
||||
encoded := hex.EncodeToString(salt)
|
||||
derived, err := scrypt.Key([]byte(password), []byte(encoded), 16384, 8, 1, 64)
|
||||
if err != nil {
|
||||
return PasswordHash{}, err
|
||||
}
|
||||
return PasswordHash{Hash: hex.EncodeToString(derived), Salt: encoded}, nil
|
||||
}
|
||||
Reference in new issue
Block a user