controller/robot: use global regexp vars (#17915)

Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>

Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
This commit is contained in:
Iceber Gu 2022-12-06 15:59:37 +08:00 committed by GitHub
parent 24a091018c
commit 7dc452ccab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -395,12 +395,12 @@ func CreateSec(salt ...string) (string, string, string, error) {
return secret, pwd, saltTmp, nil return secret, pwd, saltTmp, nil
} }
var (
hasLower = regexp.MustCompile(`[a-z]`)
hasUpper = regexp.MustCompile(`[A-Z]`)
hasNumber = regexp.MustCompile(`\d`)
)
func IsValidSec(secret string) bool { func IsValidSec(secret string) bool {
hasLower := regexp.MustCompile(`[a-z]`) return len(secret) >= 8 && hasLower.MatchString(secret) && hasUpper.MatchString(secret) && hasNumber.MatchString(secret)
hasUpper := regexp.MustCompile(`[A-Z]`)
hasNumber := regexp.MustCompile(`\d`)
if len(secret) >= 8 && hasLower.MatchString(secret) && hasUpper.MatchString(secret) && hasNumber.MatchString(secret) {
return true
}
return false
} }