2017-07-17 12:16:19 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-07-17 17:31:25 +08:00
|
|
|
"os"
|
|
|
|
"strconv"
|
2017-07-17 12:16:19 +08:00
|
|
|
|
|
|
|
"github.com/serverwentdown/pword/pw"
|
2017-10-07 16:27:46 +08:00
|
|
|
|
2017-07-17 17:31:25 +08:00
|
|
|
"github.com/urfave/cli"
|
2017-07-17 12:16:19 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2017-07-17 17:31:25 +08:00
|
|
|
app := cli.NewApp()
|
|
|
|
|
|
|
|
app.Name = "pword"
|
|
|
|
app.Usage = "generate secure passwords"
|
|
|
|
app.Version = "0.1.0"
|
|
|
|
|
2017-10-07 16:27:46 +08:00
|
|
|
app.Flags = []cli.Flag{
|
2017-07-17 17:31:25 +08:00
|
|
|
cli.StringFlag{
|
2017-10-07 16:27:46 +08:00
|
|
|
Name: "count, c",
|
2017-07-17 17:31:25 +08:00
|
|
|
Value: "auto",
|
|
|
|
Usage: "Generates `NUM` passwords for you to choose from",
|
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
2017-10-07 16:27:46 +08:00
|
|
|
Name: "1",
|
2017-07-17 17:31:25 +08:00
|
|
|
Usage: "Equivalent to --count 1",
|
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
2017-10-07 16:27:46 +08:00
|
|
|
Name: "stronger",
|
2017-07-17 17:31:25 +08:00
|
|
|
Usage: "Chooses from a list of 7,776 words instead",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
app.Commands = []cli.Command{
|
|
|
|
{
|
2017-10-07 16:27:46 +08:00
|
|
|
Name: "online",
|
2017-07-17 17:31:25 +08:00
|
|
|
Usage: "Generates passwords for use on websites",
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
return generate(c, pw.StrengthOnline)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-10-07 16:27:46 +08:00
|
|
|
Name: "offline",
|
2017-07-17 17:31:25 +08:00
|
|
|
Usage: "Generates passwords for use offline (laptops, encrypted drives)",
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
return generate(c, pw.StrengthOffline)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-10-07 16:27:46 +08:00
|
|
|
Name: "crypto",
|
2017-07-17 17:31:25 +08:00
|
|
|
Usage: "Generates extremely secure passwords",
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
return generate(c, pw.StrengthCrypto)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-10-07 16:27:46 +08:00
|
|
|
Name: "recall",
|
2017-07-17 17:31:25 +08:00
|
|
|
Usage: "Utility with autocomplete to help you recall passwords",
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
return recall(c)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
app.Run(os.Args)
|
|
|
|
}
|
|
|
|
|
|
|
|
func generate(c *cli.Context, strength pw.Strength) error {
|
|
|
|
count := int(strength)
|
|
|
|
countString := c.GlobalString("count")
|
|
|
|
countParsed, err := strconv.ParseUint(countString, 10, 64)
|
|
|
|
if err == nil {
|
|
|
|
count = int(countParsed)
|
|
|
|
}
|
|
|
|
if c.GlobalBool("1") {
|
|
|
|
count = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
mode := pw.ModeShort
|
|
|
|
if c.GlobalBool("stronger") {
|
|
|
|
mode = pw.ModeLong
|
|
|
|
}
|
2017-10-07 16:27:46 +08:00
|
|
|
|
2017-07-17 17:31:25 +08:00
|
|
|
g := pw.NewGenerator(mode, strength)
|
|
|
|
|
|
|
|
for i := 0; i < count; i++ {
|
|
|
|
pw, err := g.Next()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println(pw)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func recall(c *cli.Context) error {
|
|
|
|
return nil
|
2017-07-17 12:16:19 +08:00
|
|
|
}
|