mirror of
https://github.com/wneessen/apg-go.git
synced 2024-12-03 18:50:38 +01:00
Add support for mobile-friendly password grouping
This commit introduces a new feature "MobileGrouping" that changes the way passwords are generated to be more mobile-friendly. The `config.go` file was updated to include this new attribute, along with its corresponding method given as an Option. Additionally, the respective unit test was added ensuring the proper function of this feature.
This commit is contained in:
parent
6a8a5bb5aa
commit
0c942a47c1
2 changed files with 22 additions and 0 deletions
10
config.go
10
config.go
|
@ -53,6 +53,9 @@ type Config struct {
|
|||
// MinUpperCase represents the minimum amount of upper-case characters that have
|
||||
// to be part of the generated password
|
||||
MinUpperCase int64
|
||||
// MobileGrouping indicates if the generated password should be grouped in a
|
||||
// mobile-friendly manner
|
||||
MobileGrouping bool
|
||||
// Mode holds the different character modes for the Random algorithm
|
||||
Mode ModeMask
|
||||
// NumberPass sets the number of passwords that are generated
|
||||
|
@ -175,6 +178,13 @@ func WithMaxLength(length int64) Option {
|
|||
}
|
||||
}
|
||||
|
||||
// WithMobileGrouping enables the mobile-friendly character grouping for AlgoRandom
|
||||
func WithMobileGrouping() Option {
|
||||
return func(config *Config) {
|
||||
config.MobileGrouping = true
|
||||
}
|
||||
}
|
||||
|
||||
// WithModeMask overrides the default mode mask for the random algorithm
|
||||
func WithModeMask(mask ModeMask) Option {
|
||||
return func(config *Config) {
|
||||
|
|
|
@ -184,6 +184,18 @@ func TestWithMinUppercase(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestWithMobileGrouping(t *testing.T) {
|
||||
c := NewConfig(WithMobileGrouping())
|
||||
if c == nil {
|
||||
t.Errorf("NewConfig(WithMobileGrouping()) failed, expected config pointer but got nil")
|
||||
return
|
||||
}
|
||||
if c.MobileGrouping != true {
|
||||
t.Errorf("NewConfig(WithMobileGrouping()) failed, expected: %t, got: %t",
|
||||
true, c.MobileGrouping)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithModeMask(t *testing.T) {
|
||||
e := DefaultMode
|
||||
c := NewConfig(WithModeMask(e))
|
||||
|
|
Loading…
Reference in a new issue