v0.3.1: New password length behaviour

To address issue #13, the password length behaviour of the
original APG has been reproduced. Previously, when a minLength
of 5 and a maxLength of 10 was given, apg-go se the pwLength to
the preferred maxLength.

With v0.3.1 it will choose a random length between minLength and
maxLength instead, same as the original C-lang apg did. For this
the minLength has been defaulted to a sane value of 12 (instead
of the 8 of the original apg). The default for maxLength stayed
at 20.

Also the default number of generated passwords has been changed
from 1 to 6, to replicate the behaviour of the original apg.
This commit is contained in:
Winni Neessen 2021-04-17 11:11:54 +02:00
parent 9277e83fd4
commit eaf4a4c57d
Signed by: wneessen
GPG key ID: 385AC9889632126E
2 changed files with 9 additions and 11 deletions

View file

@ -4,13 +4,9 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="fbb0c733-4aa1-4d27-87d5-c7276d8aa613" name="Default Changelist" comment=""> <list default="true" id="fbb0c733-4aa1-4d27-87d5-c7276d8aa613" name="Default Changelist" comment="v0.3.1: New password length behaviour&#10;&#10;To address issue #13, the password length behaviour of the &#10;original APG has been reproduced. Previously, when a minLength&#10;of 5 and a maxLength of 10 was given, apg-go se the pwLength to&#10;the preferred maxLength.&#10;&#10;With v0.3.1 it will choose a random length between minLength and&#10;maxLength instead, same as the original C-lang apg did. For this&#10;the minLength has been defaulted to a sane value of 12 (instead &#10;of the 8 of the original apg). The default for maxLength stayed&#10;at 20.&#10;&#10;Also the default number of generated passwords has been changed &#10;from 1 to 6, to replicate the behaviour of the original apg.">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/apg.go" beforeDir="false" afterPath="$PROJECT_DIR$/apg.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/apg.go" beforeDir="false" afterPath="$PROJECT_DIR$/apg.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/apg_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/apg_test.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config.go" beforeDir="false" afterPath="$PROJECT_DIR$/config.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
<change beforePath="$PROJECT_DIR$/rand.go" beforeDir="false" afterPath="$PROJECT_DIR$/rand.go" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -234,7 +230,8 @@
<MESSAGE value="New DEV branch" /> <MESSAGE value="New DEV branch" />
<MESSAGE value="v0.2.9: Replaced standard go-help with custom usage text" /> <MESSAGE value="v0.2.9: Replaced standard go-help with custom usage text" />
<MESSAGE value="v0.3.0: Unified the naming convention" /> <MESSAGE value="v0.3.0: Unified the naming convention" />
<option name="LAST_COMMIT_MESSAGE" value="v0.3.0: Unified the naming convention" /> <MESSAGE value="v0.3.1: New password length behaviour&#10;&#10;To address issue #13, the password length behaviour of the &#10;original APG has been reproduced. Previously, when a minLength&#10;of 5 and a maxLength of 10 was given, apg-go se the pwLength to&#10;the preferred maxLength.&#10;&#10;With v0.3.1 it will choose a random length between minLength and&#10;maxLength instead, same as the original C-lang apg did. For this&#10;the minLength has been defaulted to a sane value of 12 (instead &#10;of the 8 of the original apg). The default for maxLength stayed&#10;at 20.&#10;&#10;Also the default number of generated passwords has been changed &#10;from 1 to 6, to replicate the behaviour of the original apg." />
<option name="LAST_COMMIT_MESSAGE" value="v0.3.1: New password length behaviour&#10;&#10;To address issue #13, the password length behaviour of the &#10;original APG has been reproduced. Previously, when a minLength&#10;of 5 and a maxLength of 10 was given, apg-go se the pwLength to&#10;the preferred maxLength.&#10;&#10;With v0.3.1 it will choose a random length between minLength and&#10;maxLength instead, same as the original C-lang apg did. For this&#10;the minLength has been defaulted to a sane value of 12 (instead &#10;of the 8 of the original apg). The default for maxLength stayed&#10;at 20.&#10;&#10;Also the default number of generated passwords has been changed &#10;from 1 to 6, to replicate the behaviour of the original apg." />
</component> </component>
<component name="VgoProject"> <component name="VgoProject">
<integration-enabled>true</integration-enabled> <integration-enabled>true</integration-enabled>

11
apg.go
View file

@ -8,8 +8,9 @@ import (
) )
// Constants // Constants
const DefaultPwLenght int = 20 const DefaultMinLenght int = 12
const VersionString string = "0.3.0" const DefaultMaxLenght int = 20
const VersionString string = "0.3.1"
type Config struct { type Config struct {
minPassLen int minPassLen int
@ -37,9 +38,9 @@ apg [-m <length>] [-x <length>] [-L] [-U] [-N] [-S] [-H] [-C]
[-l] [-M mode] [-E char_string] [-n num_of_pass] [-v] [-h] [-l] [-M mode] [-E char_string] [-n num_of_pass] [-v] [-h]
Options: Options:
-m LENGTH Minimum length of the password to be generated (Default: 20) -m LENGTH Minimum length of the password to be generated (Default: 12)
-x LENGTH Maximum length of the password to be generated (Default: 20) -x LENGTH Maximum length of the password to be generated (Default: 20)
-n NUMBER Amount of password to be generated (Default: 1) -n NUMBER Amount of password to be generated (Default: 6)
-E CHARS List of characters to be excluded in the generated password -E CHARS List of characters to be excluded in the generated password
-M [LUNSHClunshc] New style password parameters (upper case: on, lower case: off) -M [LUNSHClunshc] New style password parameters (upper case: on, lower case: off)
-L Use lower case characters in passwords (Default: on) -L Use lower case characters in passwords (Default: on)
@ -69,11 +70,11 @@ func main() {
} }
// Set PW length and available characterset // Set PW length and available characterset
pwLength := getPwLengthFromParams(&config)
charRange := getCharRange(&config) charRange := getCharRange(&config)
// Generate passwords // Generate passwords
for i := 1; i <= config.numOfPass; i++ { for i := 1; i <= config.numOfPass; i++ {
pwLength := getPwLengthFromParams(&config)
pwString, err := getRandChar(&charRange, pwLength) pwString, err := getRandChar(&charRange, pwLength)
if err != nil { if err != nil {
log.Fatalf("getRandChar returned an error: %q\n", err) log.Fatalf("getRandChar returned an error: %q\n", err)