Skip to content

Commit

Permalink
password max and min length
Browse files Browse the repository at this point in the history
  • Loading branch information
david-julien committed Dec 14, 2017
1 parent 7c306e6 commit 2cb737c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
7 changes: 5 additions & 2 deletions app/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ const (

// Password complexity constants
const (
minPasswordLen = 8
// minPasswordLen represents the min password length in characters
minPasswordLen = 10
// maxPasswordLen = 128 represents the max password length in characters
maxPasswordLen = 128
)

// Encrypt encrypts cipherText with a given password
Expand Down Expand Up @@ -97,7 +100,7 @@ func Decrypt(cipherText []byte, password string) ([]byte, error) {

// VerifyPasswordComplexity verifies password complexity
func VerifyPasswordComplexity(password string) bool {
return len(password) >= minPasswordLen
return (len(password) >= minPasswordLen) && (len(password) <= maxPasswordLen)
}

// InvalidPassword is returned from Decrypt if an invalid password is used to
Expand Down
21 changes: 19 additions & 2 deletions app/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,30 @@ func TestInvalidPassword(t *testing.T) {
}

func TestPasswordComplexity(t *testing.T) {
test := "1234567"
test := "12345679"
if app.VerifyPasswordComplexity(test) {
t.Fail()
}

test = "12345678"
test = "12345678910"
if !app.VerifyPasswordComplexity(test) {
t.Fail()
}

test = ""
for i := 0; i < 128; i++ {
test += "1"
}
if !app.VerifyPasswordComplexity(test) {
t.Fail()
}

// Test 128 character length
test = ""
for i := 0; i < 129; i++ {
test += "1"
}
if app.VerifyPasswordComplexity(test) {
t.Fail()
}
}

0 comments on commit 2cb737c

Please sign in to comment.