From 0c942a47c17563af4ac709bf6365faeed0935921 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 25 Mar 2024 11:31:31 +0100 Subject: [PATCH] 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. --- config.go | 10 ++++++++++ config_test.go | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/config.go b/config.go index a64bb0b..42607d0 100644 --- a/config.go +++ b/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) { diff --git a/config_test.go b/config_test.go index 1f43cd2..038d463 100644 --- a/config_test.go +++ b/config_test.go @@ -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))