Skip to content

Commit

Permalink
Merge pull request #24 from tcpiplab/clean_out_old_table_code
Browse files Browse the repository at this point in the history
Clean out old table code
  • Loading branch information
tcpiplab authored Mar 26, 2023
2 parents 7fca337 + f706f71 commit 21f820f
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 215 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ PS C:\Users\somebody\Downloads> .\passwordgen-v1.3.0-windows-amd64.exe -passphra
# Building releases for multiple platforms
```shell
GOOS=darwin GOARCH=arm64 go build -o Release-Binaries/v1.3.x/passwordgen-v1.3.0-darwin-arm64
GOOS=darwin GOARCH=amd64 go build -o Release-Binaries/v1.3.x/passwordgen-v1.3.0-darwin-amd64
GOOS=windows GOARCH=amd64 go build -o Release-Binaries/v1.3.x/passwordgen-v1.3.0-windows-amd64.exe
GOOS=linux GOARCH=amd64 go build -o Release-Binaries/v1.3.x/passwordgen-v1.3.0-linux-amd64
GOOS=darwin GOARCH=arm64 go build -o Release-Binaries/v1.4.x/passwordgen-v1.4.0-darwin-arm64
GOOS=darwin GOARCH=amd64 go build -o Release-Binaries/v1.4.x/passwordgen-v1.4.0-darwin-amd64
GOOS=windows GOARCH=amd64 go build -o Release-Binaries/v1.4.x/passwordgen-v1.4.0-windows-amd64.exe
GOOS=linux GOARCH=amd64 go build -o Release-Binaries/v1.4.x/passwordgen-v1.4.0-linux-amd64
```
Binary file modified Release-Binaries/v1.3.x/passwordgen-v1.3.0-windows-amd64.exe
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified passwordgen
Binary file not shown.
9 changes: 1 addition & 8 deletions passwordgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,7 @@ func main() {
if OS == "darwin" || OS == "linux" || OS == "unix" {

// Fill the screen with passwords
arrayPasswords = printPasswordTableUnix(
rows,
requestedPasswordLength,
arrayPasswords,
*randomPasswords,
*wordChains,
*mixedPasswords,
*passPhrases)
arrayPasswords = printPasswordTableUnix(arrayPasswords, *randomPasswords, *wordChains, *mixedPasswords, *passPhrases)

} else if OS == "windows" {

Expand Down
209 changes: 6 additions & 203 deletions printUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,104 +162,6 @@ func printPasswordTableWindows(
return arrayPasswords
}

// colorizeCharactersWindows() prints and does not return anything
func colorizeCharactersWindows(requestedPasswordLength int, password string) {

var coloredCharsString string

// Trim the password down to the requestedPasswordLength
//password = trimPassword(password, requestedPasswordLength)

// Check each character's ascii value and colorize according to category
for i := 0; i < requestedPasswordLength; i++ {

// Convert the character back to ascii value for the color assignment
character := int32(password[i])

// TODO: Make uppercase and lowercase Hi colors and others not Hi.

if character >= 65 && character <= 90 {

// Assign a color to uppercase characters
color.NoColor = false
uppercaseColorPrint := color.New(color.FgCyan).PrintfFunc()
uppercaseColorPrint(string(character))
color.NoColor = true

} else if character >= 97 && character <= 122 {

// Assign a color to lowercase characters
color.NoColor = false
lowercaseColorPrint := color.New(color.FgGreen).PrintfFunc()
lowercaseColorPrint(string(character))
color.NoColor = true

} else if character >= 48 && character <= 57 {

// Assign a color to number characters
color.NoColor = false
numberColorPrint := color.New(color.FgHiCyan).PrintfFunc()
numberColorPrint(string(character))
color.NoColor = true

} else if character >= 33 && character <= 47 {

if character == 37 {

// Double the % sign or printf thinks it is a formatting symbol
color.NoColor = false
specialCharColorPrint := color.New(color.FgHiGreen).PrintfFunc()
specialCharColorPrint("%%")
color.NoColor = true

} else {

// Assign a color to special characters, first range
color.NoColor = false
specialCharColorPrint := color.New(color.FgHiGreen).PrintfFunc()
specialCharColorPrint(string(character))
color.NoColor = true

}
} else if character >= 58 && character <= 64 {

// Assign a color to special characters, second range
color.NoColor = false
specialCharColorPrint := color.New(color.FgHiGreen).PrintfFunc()
specialCharColorPrint(string(character))
color.NoColor = true

} else if character >= 91 && character <= 96 {

// Assign a color to special characters, third range
color.NoColor = false
specialCharColorPrint := color.New(color.FgHiGreen).PrintfFunc()
specialCharColorPrint(string(character))
color.NoColor = true

} else if character >= 123 && character <= 126 {

// Assign a color to special characters, fourth range
color.NoColor = false
specialCharColorPrint := color.New(color.FgHiGreen).PrintfFunc()
specialCharColorPrint(string(character))
color.NoColor = true

} else {

// Assign a color to any character not represented above
color.NoColor = false
specialCharColorPrint := color.New(color.FgHiYellow).PrintfFunc()
specialCharColorPrint(string(character))
color.NoColor = true

}
color.NoColor = true
}

fmt.Print(coloredCharsString)
}

// printPasswordTableUnix prints a table of randomized passwords with index numbers to the terminal screen.
//
// The function takes in the number of rows to print, the requested length of each password,
Expand All @@ -273,107 +175,8 @@ func colorizeCharactersWindows(requestedPasswordLength int, password string) {
// - requestedPasswordLength: an int specifying the length of each password to generate
// - arrayPasswords: a slice of strings representing the passwords to be populated
// Returns: nothing
func printPasswordTableUnix(
rows int,
requestedPasswordLength int,
arrayPasswords []string,
randomPasswords bool,
wordChains bool,
mixedPasswords bool,
passPhrases bool) []string {

grey := color.New(color.FgCyan, color.Faint).SprintfFunc()
underline := grey("─")

if !passPhrases && !wordChains && !mixedPasswords && !randomPasswords {

fmt.Printf(
"%s%s%s\n",
grey("+────+"),
strings.Repeat(underline, requestedPasswordLength+2),
grey("+"),
)
}
// Loop to print rows of index numbers and passwords to the terminal screen
for rowNumber := 0; rowNumber < ((rows / 2) - 1); rowNumber++ {

if !passPhrases && !wordChains && !mixedPasswords && !randomPasswords {

red := color.New(color.FgRed).SprintFunc()
rowNumberString := fmt.Sprintf("%02d", rowNumber)

// Print an index number for each printed password
color.NoColor = false
fmt.Printf("%s %s %s ", grey("│"), red(rowNumberString), grey("│"))
}

if randomPasswords {

break

//// Fetch a new randomized password string of the specified length
//password := randStringPassword(requestedPasswordLength)
//
//arrayPasswords[rowNumber] = password
//
//// Colorize and print the password
//colorizeCharactersUnix(requestedPasswordLength, password, true)

} else if wordChains {

break

} else if mixedPasswords {

password := createMixedPassword(mixedPasswords, randomPasswords, rows)

arrayPasswords[rowNumber] = password

break
// Colorize and print the password
//colorizeCharactersUnix(requestedPasswordLength, password, true)

} else if passPhrases {
func printPasswordTableUnix(arrayPasswords []string, randomPasswords bool, wordChains bool, mixedPasswords bool, passPhrases bool) []string {

password := createPassphrase()

arrayPasswords[rowNumber] = password

break
}

// Vertical line after the password
fmt.Printf(" %s", grey("│"))

// Newline at end of row
fmt.Printf("\n")

//fmt.Printf("%s of %s %s\n", rowNumber, rows, len(arrayPasswords))

// If it's the final line we're printing
if rowNumber == (len(arrayPasswords) - 9) {

// └
fmt.Print(grey("+"))
} else if rowNumber >= 0 {

// Beginning of row line, middle of table ├
fmt.Print(grey("+"))
}

// Line under password index number, then cross line character ┼
fmt.Printf("%s%s", strings.Repeat(underline, 4), grey("+"))

// Line between rows
fmt.Printf("%s", strings.Repeat(underline, requestedPasswordLength+2))

// End of row line ┤
fmt.Printf("%s", grey("+"))

// Newline at end of row line
fmt.Printf("\n")

}
if passPhrases {

arrayPasswords = printPassphraseTable()
Expand All @@ -395,7 +198,7 @@ func printPasswordTableUnix(
return arrayPasswords
}

func colorizeCharactersUnix(requestedPasswordLength int, password string, print bool) string {
func colorizeCharactersUnix(password string, print bool) string {

var coloredCharsString string

Expand Down Expand Up @@ -497,7 +300,7 @@ func printPassphraseTable() []string {

// Colorize the passphrase that we're saving to the array
// The following works on all platforms but no color renders on Windows
passphrase = colorizeCharactersUnix(len(passphrase), passphrase, false)
passphrase = colorizeCharactersUnix(passphrase, false)

// Append the passphrase to the array
arrayOfPassphrases[i] = passphrase
Expand Down Expand Up @@ -557,7 +360,7 @@ func printWordChainsTable() []string {

// Colorize the word chain that we're saving to the array
// The following works on all platforms but no color renders on Windows
wordChainColorized := colorizeCharactersUnix(len(wordChainNoColor), wordChainNoColor, false)
wordChainColorized := colorizeCharactersUnix(wordChainNoColor, false)

// Append the word chain to the array to be used by the clipboard if in interactive mode
arrayOfWordChains[i] = wordChainNoColor
Expand Down Expand Up @@ -601,7 +404,7 @@ func printMixedPasswordsTable(mixedPasswords bool, randomPasswords bool) []strin

// Colorize the mixed password that we're saving to the array
// The following works on all platforms but no color renders on Windows
mixedPasswordColorized := colorizeCharactersUnix(len(mixedPasswordNoColor), mixedPasswordNoColor, false)
mixedPasswordColorized := colorizeCharactersUnix(mixedPasswordNoColor, false)

// Append the mixed password to the array to be used by the clipboard if in interactive mode
arrayOfMixedPasswords[i] = mixedPasswordNoColor
Expand Down Expand Up @@ -645,7 +448,7 @@ func printRandomPasswordsTable() []string {

// Colorize the random password that we're saving to the array
// The following works on all platforms but no color renders on Windows
randomPasswordColorized := colorizeCharactersUnix(len(randomPasswordNoColor), randomPasswordNoColor, false)
randomPasswordColorized := colorizeCharactersUnix(randomPasswordNoColor, false)

// Append the random password to the array to be used by the clipboard if in interactive mode
arrayOfRandomPasswords[i] = randomPasswordNoColor
Expand Down

0 comments on commit 21f820f

Please sign in to comment.