add go.mod and remove unnecessary dep

This commit is contained in:
ChenYe 2022-04-13 22:35:28 +08:00
parent 2972be24d4
commit a11d8f26cf
3 changed files with 21 additions and 12 deletions

View File

@ -23,7 +23,6 @@ import (
"fmt" "fmt"
"github.com/chzyer/readline" "github.com/chzyer/readline"
zxcvbn "github.com/nbutton23/zxcvbn-go"
) )
const ( const (
@ -50,30 +49,24 @@ func Colorize(msg string, color int) string {
func createStrengthPrompt(password []rune) string { func createStrengthPrompt(password []rune) string {
symbol, color := "", Red symbol, color := "", Red
strength := zxcvbn.PasswordStrength(string(password), nil)
switch { switch {
case strength.Score <= 1: case len(password) <= 1:
symbol = "✗" symbol = "✗"
color = Red color = Red
case strength.Score <= 2: case len(password) <= 3:
symbol = "⚡" symbol = "⚡"
color = Magenta color = Magenta
case strength.Score <= 3: case len(password) <= 5:
symbol = "⚠" symbol = "⚠"
color = Yellow color = Yellow
case strength.Score <= 4: default:
symbol = "✔" symbol = "✔"
color = Green color = Green
} }
prompt := Colorize(symbol, color) prompt := Colorize(symbol, color)
if strength.Entropy > 0 { prompt += Colorize(" ENT", Cyan)
entropy := fmt.Sprintf(" %3.0f", strength.Entropy)
prompt += Colorize(entropy, Cyan)
} else {
prompt += Colorize(" ENT", Cyan)
}
prompt += Colorize(" New Password: ", color) prompt += Colorize(" New Password: ", color)
return prompt return prompt

10
go.mod Normal file
View File

@ -0,0 +1,10 @@
module github.com/chzyer/readline
go 1.15
require (
github.com/chzyer/test v0.0.0-20210722231415-061457976a23
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5
)
require github.com/chzyer/logex v1.2.0

6
go.sum Normal file
View File

@ -0,0 +1,6 @@
github.com/chzyer/logex v1.2.0 h1:+eqR0HfOetur4tgnC8ftU5imRnhi4te+BadWS95c5AM=
github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY=
github.com/chzyer/test v0.0.0-20210722231415-061457976a23 h1:dZ0/VyGgQdVGAss6Ju0dt5P0QltE0SFY5Woh6hbIfiQ=
github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=