(label string, compareTo string)
| 31 | ) |
| 32 | |
| 33 | func PromptPassword(label string, compareTo string) (string, error) { |
| 34 | if label == "" { |
| 35 | label = "Password" |
| 36 | } |
| 37 | validate := func(input string) error { |
| 38 | passwordStenght := zxcvbn.PasswordStrength(input, nil) |
| 39 | if passwordStenght.Score < 4 { |
| 40 | return errors.New("password is too weak") |
| 41 | } |
| 42 | if compareTo != "" && compareTo != input { |
| 43 | return errors.New("passwords do not match") |
| 44 | } |
| 45 | return nil |
| 46 | } |
| 47 | |
| 48 | prompt := promptui.Prompt{ |
| 49 | Label: label, |
| 50 | Validate: validate, |
| 51 | Mask: '*', |
| 52 | } |
| 53 | result, err := prompt.Run() |
| 54 | if err != nil { |
| 55 | return "", err |
| 56 | } |
| 57 | return result, nil |
| 58 | } |
| 59 | |
| 60 | func PromptString(label string, a ...interface{}) (string, error) { |
| 61 | validate := func(input string) error { |
no test coverage detected