Skip to content

Commit

Permalink
add go.mod and remove unnecessary dep
Browse files Browse the repository at this point in the history
  • Loading branch information
chzyer committed Apr 13, 2022
1 parent 2972be2 commit a11d8f2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
17 changes: 5 additions & 12 deletions example/readline-pass-strength/readline-pass-strength.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"fmt"

"github.com/chzyer/readline"
zxcvbn "github.com/nbutton23/zxcvbn-go"
)

const (
Expand All @@ -50,30 +49,24 @@ func Colorize(msg string, color int) string {

func createStrengthPrompt(password []rune) string {
symbol, color := "", Red
strength := zxcvbn.PasswordStrength(string(password), nil)

switch {
case strength.Score <= 1:
case len(password) <= 1:
symbol = "✗"
color = Red
case strength.Score <= 2:
case len(password) <= 3:
symbol = "⚡"
color = Magenta
case strength.Score <= 3:
case len(password) <= 5:
symbol = "⚠"
color = Yellow
case strength.Score <= 4:
default:
symbol = "✔"
color = Green
}

prompt := Colorize(symbol, color)
if strength.Entropy > 0 {
entropy := fmt.Sprintf(" %3.0f", strength.Entropy)
prompt += Colorize(entropy, Cyan)
} else {
prompt += Colorize(" ENT", Cyan)
}
prompt += Colorize(" ENT", Cyan)

prompt += Colorize(" New Password: ", color)
return prompt
Expand Down
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=

0 comments on commit a11d8f2

Please sign in to comment.