1
0
Fork 0
mirror of https://github.com/Luzifer/password.git synced 2024-11-09 18:00:03 +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().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.XKCD, "xkcd", "x", false, "use XKCD style password")
@ -33,6 +34,8 @@ func actionCmdGet(cmd *cobra.Command, args []string) {
err error
)
for i := 0; i < flags.CLI.Num; i++ {
if flags.CLI.XKCD {
password, err = pwd.DefaultXKCD.GeneratePassword(flags.CLI.Length, flags.CLI.PrependDate)
} else {
@ -51,7 +54,7 @@ func actionCmdGet(cmd *cobra.Command, args []string) {
if !flags.CLI.JSON {
fmt.Println(password)
os.Exit(0)
continue
}
hashes, err := hasher.GetHashMap(password)
@ -61,4 +64,6 @@ func actionCmdGet(cmd *cobra.Command, args []string) {
}
hashes["password"] = password
json.NewEncoder(os.Stdout).Encode(hashes)
}
}

View file

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