Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GGP1 committed Jan 16, 2021
1 parent a778f24 commit 40133b6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion atoll.go
Expand Up @@ -5,7 +5,7 @@ package atoll
import "math"

// 1 trillion is the number of guesses per second Edward Snowden said we should be prepared for.
const guessesPerSecond = 1000000000000000
const guessesPerSecond = 1000000000000

// Secret is the interface that wraps the basic method Generate.
type Secret interface {
Expand Down
10 changes: 4 additions & 6 deletions password.go
Expand Up @@ -255,8 +255,6 @@ func (p *Password) validateLevels(levels map[int]struct{}) error {
)

for l := range levels {
fail := true

switch l {
case 1:
set = lowerCase
Expand All @@ -274,14 +272,14 @@ func (p *Password) validateLevels(levels map[int]struct{}) error {
levelName = "special"
}

counter := 0
for _, excl := range p.Exclude {
if !strings.Contains(set, string(excl)) {
fail = false
break
if strings.Contains(set, string(excl)) {
counter++
}
}

if fail {
if counter == len(set) {
return fmt.Errorf("%s level is used and all its characters are excluded", levelName)
}
}
Expand Down
6 changes: 3 additions & 3 deletions password_test.go
Expand Up @@ -160,13 +160,13 @@ func TestInvalidPassword(t *testing.T) {
},
"digit level is used and all the characters are excluded": {
Length: 10,
Format: []int{3, 4},
Exclude: digit,
Format: []int{1, 3, 4},
Exclude: digit + "aB",
},
"space level is used and all the characters are excluded": {
Length: 1,
Format: []int{4},
Exclude: space,
Exclude: space + "/",
},
"special level is used and all the characters are excluded": {
Length: 20,
Expand Down

0 comments on commit 40133b6

Please sign in to comment.