mirror of
https://github.com/wneessen/apg-go.git
synced 2024-11-23 06:10:49 +01:00
Add mobile-friendly password grouping feature
This commit introduces a new mobile grouping feature in our password generator package. Furthermore, a new unit test was added to the 'random_test.go' file to validate this functionality. This change allows users to better handle passwords on mobile devices by altering their formation.
This commit is contained in:
parent
0c942a47c1
commit
3c437e7238
2 changed files with 24 additions and 0 deletions
|
@ -354,6 +354,9 @@ func (g *Generator) generateRandom() (string, error) {
|
|||
ok = g.checkMinimumRequirements(password)
|
||||
}
|
||||
|
||||
if g.config.MobileGrouping {
|
||||
return GroupCharsForMobile(password), nil
|
||||
}
|
||||
return password, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -453,6 +453,27 @@ func TestGenerateRandom(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGenerateRandom_withGrouping(t *testing.T) {
|
||||
config := NewConfig(WithAlgorithm(AlgoRandom), WithMinLength(1),
|
||||
WithMaxLength(1), WithMobileGrouping())
|
||||
config.MinNumeric = 1
|
||||
generator := New(config)
|
||||
pw, err := generator.generateRandom()
|
||||
if err != nil {
|
||||
t.Errorf("generateRandom() failed: %s", err)
|
||||
}
|
||||
if len(pw) > 1 {
|
||||
t.Errorf("expected password with length 1 but got: %d", len(pw))
|
||||
}
|
||||
n, err := strconv.Atoi(pw)
|
||||
if err != nil {
|
||||
t.Errorf("expected password to be a number but got an error: %s", err)
|
||||
}
|
||||
if n < 0 || n > 9 {
|
||||
t.Errorf("expected password to be a number between 0 and 9, got: %d", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
Loading…
Reference in a new issue