Skip to content

Commit

Permalink
Add mutex to deriveArgon2IDKey
Browse files Browse the repository at this point in the history
  • Loading branch information
patapancakes committed Apr 19, 2024
1 parent 0fec7cb commit fbd4a60
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion api/account/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package account

import (
"regexp"
"sync"

"golang.org/x/crypto/argon2"
)
Expand All @@ -21,8 +22,14 @@ const (
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 {
argonMtx.Lock()
defer argonMtx.Unlock()

return argon2.IDKey(password, salt, ArgonTime, ArgonMemory, ArgonThreads, ArgonKeySize)
}

0 comments on commit fbd4a60

Please sign in to comment.