Skip to content

Commit

Permalink
feat(company): Add postal flag
Browse files Browse the repository at this point in the history
  • Loading branch information
qu35t-code committed Jun 17, 2024
1 parent 1532bb1 commit f7ef83a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmd/company.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
includeYearRange int
includeNumbers bool
includeNumbersRange int
includePostal int
)

var companyCmd = &cobra.Command{
Expand Down Expand Up @@ -55,6 +56,11 @@ var companyCmd = &cobra.Command{
fmt.Println("You cannot use both --year and --numbers")
return
}

if includeYear && includePostal != 0 {
fmt.Println("You cannot use both --year and --postal")
return
}
// End Temp

wordlist := generateCompanyPasslist(companyName)
Expand Down Expand Up @@ -100,6 +106,7 @@ func init() {
companyCmd.Flags().StringVarP(&includeMask, "mask", "m", "", "Apply a custom mask to the passwords")
companyCmd.Flags().BoolVar(&includeNumbers, "numbers", false, "Include numbers to the passwords")
companyCmd.Flags().IntVar(&includeNumbersRange, "numbers-range", 20, "Apply a range for numbers option")
companyCmd.Flags().IntVarP(&includePostal, "postal", "p", 0, "Include postal code to the passwords")

}

Expand All @@ -124,6 +131,10 @@ func generateCompanyPasslist(name string) []string {
wordlist = generate.WithUppercase(wordlist)
}

if includePostal != 0 {
wordlist = generate.WithPostal(wordlist, includePostal)
}

if includeNumbers && includeNumbersRange != 0 {
wordlist = generate.WithNumbers(wordlist, includeNumbersRange)
}
Expand Down
19 changes: 19 additions & 0 deletions cmd/company_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ func cleanup() {
includeUppercase = false
includeMask = ""
includeYearRange = 0
includePostal = 0
includeNumbers = false
includeNumbersRange = 20
}

func TestWithoutFlag(t *testing.T) {
Expand Down Expand Up @@ -226,3 +229,19 @@ func TestNumbersRangeFlag(t *testing.T) {

t.Cleanup(cleanup)
}

func TestPostalFlag(t *testing.T) {
includePostal = 75000

wordlist := generateCompanyPasslist("demo")

got := strings.Join(wordlist, "\n")

expected := "demo\ndemo75000"

if got != expected {
t.Errorf("Expected %q, but got %q", expected, got)
}

t.Cleanup(cleanup)
}
7 changes: 7 additions & 0 deletions lib/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,10 @@ func WithUppercase(wordlist []string) []string {
}
return wordlist
}

func WithPostal(wordlist []string, includePostal int) []string {
for _, word := range wordlist {
wordlist = append(wordlist, word+strconv.Itoa(includePostal))
}
return wordlist
}

0 comments on commit f7ef83a

Please sign in to comment.