Gen passwd until it satisfies metabase policy (#792)

Signed-off-by: Shivam Sandbhor <shivam@crowdsec.net>
This commit is contained in:
Shivam Sandbhor 2021-05-17 15:13:53 +05:30 committed by GitHub
parent 4433e3bf87
commit 98277f5bb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,6 +8,7 @@ import (
"path/filepath"
"strconv"
"strings"
"unicode"
"github.com/AlecAivazis/survey/v2"
"github.com/crowdsecurity/crowdsec/pkg/metabase"
@ -86,7 +87,11 @@ cscli dashboard setup -l 0.0.0.0 -p 443 --password <password>
}
if metabasePassword == "" {
metabasePassword = generatePassword(16)
isValid := passwordIsValid(metabasePassword)
for !isValid {
metabasePassword = generatePassword(16)
isValid = passwordIsValid(metabasePassword)
}
}
var answer bool
groupExist := false
@ -251,3 +256,19 @@ cscli dashboard remove --force
return cmdDashboard
}
func passwordIsValid(password string) bool {
hasDigit := false
for _, j := range password {
if unicode.IsDigit(j) {
hasDigit = true
break
}
}
if !hasDigit || len(password) < 6 {
return false
}
return true
}