@@ -175,7 +175,7 @@ func printPasswordTableWindows(
175175// - requestedPasswordLength: an int specifying the length of each password to generate
176176// - arrayPasswords: a slice of strings representing the passwords to be populated
177177// Returns: nothing
178- func printPasswordTableUnix (arrayPasswords []string , randomPasswords bool , wordChains bool , mixedPasswords bool , passPhrases bool , memorable bool ) []string {
178+ func printPasswordTableUnix (arrayPasswords []string , randomPasswords bool , wordChains bool , mixedPasswords bool , passPhrases bool , memorable bool , randomHex bool ) []string {
179179
180180 if passPhrases {
181181
@@ -196,6 +196,11 @@ func printPasswordTableUnix(arrayPasswords []string, randomPasswords bool, wordC
196196 } else if memorable {
197197
198198 arrayPasswords = printMemorableTable ()
199+
200+ } else if randomHex {
201+
202+ arrayPasswords = printRandomHexTable ()
203+
199204 }
200205
201206 return arrayPasswords
@@ -447,7 +452,7 @@ func printRandomPasswordsTable() []string {
447452 // Loop through the console screen height and print a table of random passwords
448453 for i := 0 ; i < (consoleHeight / 2 )- 1 ; i ++ {
449454
450- randomPasswordNoColor := randStringPassword (requestedPasswordLength )
455+ randomPasswordNoColor := randStringPassword (requestedPasswordLength , false )
451456
452457 // Colorize the random password that we're saving to the array
453458 // The following works on all platforms but no color renders on Windows
@@ -515,3 +520,49 @@ func printMemorableTable() []string {
515520 // clipboard functions if we're in interactive mode.
516521 return arrayOfMemorablePasswords
517522}
523+
524+ func printRandomHexTable () []string {
525+ // TODO this function could be combined with printRandomPasswordTable() in some way
526+
527+ var consoleHeight int
528+
529+ // Set the console height
530+ consoleHeight = funcName (consoleHeight )
531+
532+ // Instantiate a new table writer object
533+ tableWriter := table .NewWriter ()
534+ tableWriter .SetOutputMirror (os .Stdout )
535+
536+ // Create a new empty array with the same length as the original array
537+ // This avoids leftover empty array elements causing clipboard copy
538+ // failures later on.
539+ arrayOfRandomHex := make ([]string , consoleHeight / 2 )
540+
541+ // Loop through the console screen height and print a table of random hex passwords
542+ for i := 0 ; i < (consoleHeight / 2 )- 1 ; i ++ {
543+
544+ // TODO: Call a new function for randStringHex() here
545+ randomHexNoColor := randStringPassword (requestedPasswordLength , true )
546+
547+ // Colorize the random hex passwords that we're saving to the array
548+ // The following works on all platforms but no color renders on Windows
549+ randomHexColorized := colorizeCharactersUnix (randomHexNoColor , false )
550+
551+ // Append the random hex password to the array to be used by the clipboard if in interactive mode
552+ arrayOfRandomHex [i ] = randomHexNoColor
553+
554+ // Prepare color for the index number
555+ red := color .New (color .FgHiRed ).SprintfFunc ()
556+
557+ // Print the index number and current element of the array
558+ tableWriter .AppendRow ([]interface {}{red ("%d" , i ), randomHexColorized })
559+
560+ tableWriter .AppendSeparator ()
561+ }
562+ tableWriter .SetStyle (table .StyleLight )
563+ tableWriter .Render ()
564+
565+ // Return the array because it's needed for the
566+ // clipboard functions if we're in interactive mode.
567+ return arrayOfRandomHex
568+ }
0 commit comments