|
|
@ -2,6 +2,7 @@ package account
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
"regexp"
|
|
|
|
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
|
|
|
|
"golang.org/x/crypto/argon2"
|
|
|
|
"golang.org/x/crypto/argon2"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -21,8 +22,14 @@ const (
|
|
|
|
TokenSize = 32
|
|
|
|
TokenSize = 32
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var isValidUsername = regexp.MustCompile(`^\w{1,16}$`).MatchString
|
|
|
|
var (
|
|
|
|
|
|
|
|
isValidUsername = regexp.MustCompile(`^\w{1,16}$`).MatchString
|
|
|
|
|
|
|
|
argonMtx sync.Mutex
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func deriveArgon2IDKey(password, salt []byte) []byte {
|
|
|
|
func deriveArgon2IDKey(password, salt []byte) []byte {
|
|
|
|
|
|
|
|
argonMtx.Lock()
|
|
|
|
|
|
|
|
defer argonMtx.Unlock()
|
|
|
|
|
|
|
|
|
|
|
|
return argon2.IDKey(password, salt, ArgonTime, ArgonMemory, ArgonThreads, ArgonKeySize)
|
|
|
|
return argon2.IDKey(password, salt, ArgonTime, ArgonMemory, ArgonThreads, ArgonKeySize)
|
|
|
|
}
|
|
|
|
}
|
|
|
|