summaryrefslogtreecommitdiff
path: root/passphrasegen.go
diff options
context:
space:
mode:
authorMichaël Ball <michael.ball@gmail.com>2017-01-07 18:07:51 +0000
committerMichaël Ball <michael.ball@gmail.com>2017-01-07 18:07:51 +0000
commitb57ee0ffc26098560202c751de9142c88d80bcc6 (patch)
tree5ed722cfc8d9a262821e5c14cc687b7fd6f6b5ab /passphrasegen.go
parent6068ab484fa377917514753becf61d2211460218 (diff)
parent7e0c7250e1a9afd9930fbb200c5cbd9a8095404e (diff)
Merge branch 'release/0.2.0'0.2.0
Diffstat (limited to 'passphrasegen.go')
-rw-r--r--passphrasegen.go35
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, " "))
}