Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Require minimum length of 8 characters password #2009

Merged
merged 9 commits into from
Dec 6, 2021
18 changes: 7 additions & 11 deletions selfservice/strategy/password/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ package password
import (
"bufio"
"context"
"time"

"github.com/hashicorp/go-retryablehttp"

"github.com/ory/kratos/driver/config"

/* #nosec G505 sha1 is used for k-anonymity */
"crypto/sha1"
Expand All @@ -16,15 +11,16 @@ import (
"strconv"
"strings"
"sync"
"time"

"github.com/arbovm/levenshtein"

"github.com/hashicorp/go-retryablehttp"
"github.com/ory/herodot"
"github.com/ory/x/httpx"

"github.com/ory/x/stringsx"
"github.com/pkg/errors"

"github.com/ory/herodot"
"github.com/ory/x/stringsx"
"github.com/ory/kratos/driver/config"
)

// Validator implements a validation strategy for passwords. One example is that the password
Expand Down Expand Up @@ -145,8 +141,8 @@ func (s *DefaultPasswordValidator) fetch(hpw []byte, apiDNSName string) error {
}

func (s *DefaultPasswordValidator) Validate(ctx context.Context, identifier, password string) error {
if len(password) < 6 {
return errors.Errorf("password length must be at least 6 characters but only got %d", len(password))
if len(password) < 8 {
return errors.Errorf("password length must be at least 8 characters but only got %d", len(password))
}

compIdentifier, compPassword := strings.ToLower(identifier), strings.ToLower(password)
Expand Down
3 changes: 1 addition & 2 deletions selfservice/strategy/password/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"time"

"github.com/ory/x/httpx"

"github.com/stretchr/testify/require"

"github.com/ory/kratos/driver/config"
Expand Down Expand Up @@ -42,6 +41,7 @@ func TestDefaultPasswordValidationStrategy(t *testing.T) {
{pw: "password", pass: false},
{pw: "1234567890", pass: false},
{pw: "qwertyui", pass: false},
{pw: "l3f9to", pass: false},
{pw: "l3f9toh1uaf81n21", pass: true},
{pw: "l3f9toh1uaf81n21", id: "l3f9toh1uaf81n21", pass: false},
{pw: "l3f9toh1", pass: true},
Expand All @@ -63,7 +63,6 @@ func TestDefaultPasswordValidationStrategy(t *testing.T) {
{id: "asdflasdflasdf", pw: "asdflasdflpiuhefnciluaksdzuföfhg", pass: true},
} {
t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) {
t.Parallel()
aeneasr marked this conversation as resolved.
Show resolved Hide resolved
err := s.Validate(context.Background(), tc.id, tc.pw)
if tc.pass {
require.NoError(t, err, "err: %+v, id: %s, pw: %s", err, tc.id, tc.pw)
Expand Down