1
0
Fork 0
master
Ambrose Chua 2017-10-07 16:27:46 +08:00
parent 8d9f9e6dde
commit 5a5b66cfbf
3 changed files with 21 additions and 21 deletions

View File

@ -1,19 +1,19 @@
package pw package pw
//go:generate go run words_generate.go //go:generate go run words_generate.go
import ( import (
"strings"
"crypto/rand" "crypto/rand"
"math/big" "math/big"
"strings"
) )
type Strength int type Strength int
const ( const (
StrengthOnline Strength = 4 StrengthOnline Strength = 4
StrengthOffline Strength = 6 StrengthOffline Strength = 6
StrengthCrypto Strength = 8 StrengthCrypto Strength = 8
) )
type Mode int type Mode int
@ -30,7 +30,7 @@ type Generator struct {
func NewGenerator(m Mode, s Strength) Generator { func NewGenerator(m Mode, s Strength) Generator {
return Generator{ return Generator{
Mode: m, Mode: m,
Strength: s, Strength: s,
} }
} }

View File

@ -4,9 +4,9 @@ package main
import ( import (
"log" "log"
"os"
"bufio" "bufio"
"os"
"text/template" "text/template"
"time" "time"
) )
@ -22,13 +22,13 @@ func main() {
defer f.Close() defer f.Close()
packageTemplate.Execute(f, struct { packageTemplate.Execute(f, struct {
Timestamp time.Time Timestamp time.Time
WordsShort []string WordsShort []string
WordsLong []string WordsLong []string
}{ }{
Timestamp: time.Now(), Timestamp: time.Now(),
WordsShort: wordsShort, WordsShort: wordsShort,
WordsLong: wordsLong, WordsLong: wordsLong,
}) })
} }

View File

@ -6,7 +6,7 @@ import (
"strconv" "strconv"
"github.com/serverwentdown/pword/pw" "github.com/serverwentdown/pword/pw"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -17,46 +17,46 @@ func main() {
app.Usage = "generate secure passwords" app.Usage = "generate secure passwords"
app.Version = "0.1.0" app.Version = "0.1.0"
app.Flags = []cli.Flag { app.Flags = []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "count, c", Name: "count, c",
Value: "auto", Value: "auto",
Usage: "Generates `NUM` passwords for you to choose from", Usage: "Generates `NUM` passwords for you to choose from",
}, },
cli.BoolFlag{ cli.BoolFlag{
Name: "1", Name: "1",
Usage: "Equivalent to --count 1", Usage: "Equivalent to --count 1",
}, },
cli.BoolFlag{ cli.BoolFlag{
Name: "stronger", Name: "stronger",
Usage: "Chooses from a list of 7,776 words instead", Usage: "Chooses from a list of 7,776 words instead",
}, },
} }
app.Commands = []cli.Command{ app.Commands = []cli.Command{
{ {
Name: "online", Name: "online",
Usage: "Generates passwords for use on websites", Usage: "Generates passwords for use on websites",
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
return generate(c, pw.StrengthOnline) return generate(c, pw.StrengthOnline)
}, },
}, },
{ {
Name: "offline", Name: "offline",
Usage: "Generates passwords for use offline (laptops, encrypted drives)", Usage: "Generates passwords for use offline (laptops, encrypted drives)",
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
return generate(c, pw.StrengthOffline) return generate(c, pw.StrengthOffline)
}, },
}, },
{ {
Name: "crypto", Name: "crypto",
Usage: "Generates extremely secure passwords", Usage: "Generates extremely secure passwords",
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
return generate(c, pw.StrengthCrypto) return generate(c, pw.StrengthCrypto)
}, },
}, },
{ {
Name: "recall", Name: "recall",
Usage: "Utility with autocomplete to help you recall passwords", Usage: "Utility with autocomplete to help you recall passwords",
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
return recall(c) return recall(c)
@ -82,7 +82,7 @@ func generate(c *cli.Context, strength pw.Strength) error {
if c.GlobalBool("stronger") { if c.GlobalBool("stronger") {
mode = pw.ModeLong mode = pw.ModeLong
} }
g := pw.NewGenerator(mode, strength) g := pw.NewGenerator(mode, strength)
for i := 0; i < count; i++ { for i := 0; i < count; i++ {