1
0
Fork 0
mirror of https://github.com/Luzifer/password.git synced 2024-11-10 02:10:00 +00:00

Add commandline flag to generate multiple passwords

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2017-10-31 12:57:19 +01:00
parent c73955d8af
commit f9c435af1a
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 29 additions and 23 deletions

View file

@ -19,6 +19,7 @@ func getCmdGet() *cobra.Command {
cmd.Flags().BoolVarP(&flags.CLI.JSON, "json", "j", false, "return output in JSON format") cmd.Flags().BoolVarP(&flags.CLI.JSON, "json", "j", false, "return output in JSON format")
cmd.Flags().IntVarP(&flags.CLI.Length, "length", "l", 20, "length of the generated password") cmd.Flags().IntVarP(&flags.CLI.Length, "length", "l", 20, "length of the generated password")
cmd.Flags().IntVarP(&flags.CLI.Num, "number", "n", 1, "number of passwords to generate")
cmd.Flags().BoolVarP(&flags.CLI.SpecialCharacters, "special", "s", false, "use special characters in your password") cmd.Flags().BoolVarP(&flags.CLI.SpecialCharacters, "special", "s", false, "use special characters in your password")
cmd.Flags().BoolVarP(&flags.CLI.XKCD, "xkcd", "x", false, "use XKCD style password") cmd.Flags().BoolVarP(&flags.CLI.XKCD, "xkcd", "x", false, "use XKCD style password")
@ -33,6 +34,8 @@ func actionCmdGet(cmd *cobra.Command, args []string) {
err error err error
) )
for i := 0; i < flags.CLI.Num; i++ {
if flags.CLI.XKCD { if flags.CLI.XKCD {
password, err = pwd.DefaultXKCD.GeneratePassword(flags.CLI.Length, flags.CLI.PrependDate) password, err = pwd.DefaultXKCD.GeneratePassword(flags.CLI.Length, flags.CLI.PrependDate)
} else { } else {
@ -51,7 +54,7 @@ func actionCmdGet(cmd *cobra.Command, args []string) {
if !flags.CLI.JSON { if !flags.CLI.JSON {
fmt.Println(password) fmt.Println(password)
os.Exit(0) continue
} }
hashes, err := hasher.GetHashMap(password) hashes, err := hasher.GetHashMap(password)
@ -61,4 +64,6 @@ func actionCmdGet(cmd *cobra.Command, args []string) {
} }
hashes["password"] = password hashes["password"] = password
json.NewEncoder(os.Stdout).Encode(hashes) json.NewEncoder(os.Stdout).Encode(hashes)
}
} }

View file

@ -5,6 +5,7 @@ var flags = struct {
Length int Length int
SpecialCharacters bool SpecialCharacters bool
JSON bool JSON bool
Num int
XKCD bool XKCD bool
PrependDate bool PrependDate bool