Gen passwd until it satisfies metabase policy (#792)
Signed-off-by: Shivam Sandbhor <shivam@crowdsec.net>
This commit is contained in:
parent
4433e3bf87
commit
98277f5bb7
|
@ -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
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue