diff options
Diffstat (limited to 'passphrasegen.go')
-rw-r--r-- | passphrasegen.go | 35 |
1 files changed, 4 insertions, 31 deletions
diff --git a/passphrasegen.go b/passphrasegen.go index 32d708e..89b25d2 100644 --- a/passphrasegen.go +++ b/passphrasegen.go @@ -1,39 +1,20 @@ package main import ( - "bufio" "flag" "fmt" - "math/rand" - "os" "strings" - "time" + + generator "github.com/michael-ball/passphrasegen/generator" ) var numWords = flag.Int("w", 4, "Number of words in passphrase") -func readLines(path string) ([]string, error) { - file, err := os.Open(path) - if err != nil { - return nil, err - } - defer file.Close() - - var lines []string - scanner := bufio.NewScanner(file) - for scanner.Scan() { - lines = append(lines, scanner.Text()) - } - return lines, scanner.Err() -} - func init() { - rand.Seed(time.Now().UTC().UnixNano()) + flag.Parse() } func main() { - flag.Parse() - args := flag.Args() wordsFile := "/usr/share/dict/words" @@ -42,20 +23,12 @@ func main() { wordsFile = args[0] } - words, err := readLines(wordsFile) + phraseWords, err := generator.RandomWords(wordsFile, *numWords) if err != nil { fmt.Println(err) return } - phraseWords := make([]string, *numWords) - - for index := 0; index < *numWords; index++ { - randInt := rand.Intn((len(words) - 1)) - - phraseWords[index] = words[randInt] - } - fmt.Println(strings.Join(phraseWords, " ")) } |