package main import ( "flag" "fmt" "gitea.stuzer.link/stuzer05/passgen/dictionary" "gitea.stuzer.link/stuzer05/passgen/dictionary/sets" ) func main() { // password flags flagLen := flag.Int("L", 16, "length of the generated password") flagCount := flag.Int("c", 1, "how many passwords to generate") // set flags flagSetAll := flag.Bool("all", false, "use all character sets") flagSetAsciiLowercase := flag.Bool("l", false, "use lowercase ascii characters") flagSetAsciiUppercase := flag.Bool("U", false, "use uppercase ascii characters") flagSetNumbers := flag.Bool("n", false, "use numbers") flagSetSpecialChars := flag.Bool("s", false, "use special characters") flagSetSpaces := flag.Bool("S", false, "use spaces") flagSetUnicodeCyrillic := flag.Bool("unicode-cyrillic", false, "use unicode cyrillic characters") flagSetUnicodeJapanese := flag.Bool("unicode-japanese", false, "use unicode Japanese characters") flagSetUnicodeChinese := flag.Bool("unicode-chinese", false, "use unicode Chinese characters") flagSetUnicodeEmoji := flag.Bool("unicode-emoji", false, "use unicode emoji characters") flag.Parse() // check password length if *flagLen <= 0 { fmt.Println("password length must be at least 1") } // check password count if *flagCount <= 0 { fmt.Println("passwords count must be at least 1") } // use all character sets if *flagSetAll { *flagSetAsciiLowercase = true *flagSetAsciiUppercase = true *flagSetNumbers = true *flagSetSpecialChars = true *flagSetSpaces = true *flagSetUnicodeCyrillic = true *flagSetUnicodeJapanese = true *flagSetUnicodeChinese = true *flagSetUnicodeEmoji = true } // use default password preset no sets were requested if !*flagSetAll && !*flagSetAsciiLowercase && !*flagSetAsciiUppercase && !*flagSetNumbers && !*flagSetSpecialChars && !*flagSetSpaces && !*flagSetUnicodeCyrillic && !*flagSetUnicodeJapanese && !*flagSetUnicodeChinese && !*flagSetUnicodeEmoji { *flagSetAsciiLowercase = true *flagSetAsciiUppercase = true *flagSetNumbers = true } // select dictionaries var characterSets [][]int if *flagSetAsciiLowercase { characterSets = append(characterSets, dictionary.ShuffleDictionarySet(sets.AsciiLowercase())) } if *flagSetAsciiUppercase { characterSets = append(characterSets, dictionary.ShuffleDictionarySet(sets.AsciiUppercase())) } if *flagSetNumbers { characterSets = append(characterSets, dictionary.ShuffleDictionarySet(sets.Numbers())) } if *flagSetSpecialChars { characterSets = append(characterSets, dictionary.ShuffleDictionarySet(sets.SpecialChars())) } if *flagSetSpaces { characterSets = append(characterSets, dictionary.ShuffleDictionarySet(sets.Space())) } // unicode if *flagSetUnicodeCyrillic { characterSets = append(characterSets, dictionary.ShuffleDictionarySet(sets.Cyrillic())) } if *flagSetUnicodeJapanese { characterSets = append(characterSets, dictionary.ShuffleDictionarySet(sets.Japanese())) } if *flagSetUnicodeChinese { characterSets = append(characterSets, dictionary.ShuffleDictionarySet(sets.Chinese())) } if *flagSetUnicodeEmoji { characterSets = append(characterSets, dictionary.ShuffleDictionarySet(sets.Emoji())) } // generate passwords for i := 0; i < *flagCount; i++ { password := generatePassword(characterSets, *flagLen) for _, i := range password { fmt.Printf("%c", i) } // new line if i < *flagCount { fmt.Print("\n") } } }