diff --git a/README.md b/README.md index 969e58e..34acb23 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ * specify number of words * different languages: English, German * specify a delimeter between words +* use an external file as word list ## how to use it @@ -13,6 +14,8 @@ Usage of ./mnemonic: -d string delimeter as split element for the password (default "-") + -f string + path to external word list -l string language of word list: [en, de] (default "en") -n uint @@ -56,5 +59,4 @@ This should drop a binary in the project directory named `mnemonic`. * provide a `-m`, `--max` parameter for setting a characterlimit. Useful for websites with password character limit. * tests, tests.. tests * build release binaries magically via github actions -* specify your own word list via `-f`, `--file` parameter * option for generating random numbers as padding/delimeter \ No newline at end of file diff --git a/main.go b/main.go index 9b5d70b..a3ed457 100644 --- a/main.go +++ b/main.go @@ -5,24 +5,33 @@ import ( "bytes" "flag" "fmt" + "io/ioutil" "log" "math/rand" "time" ) -func newWordList(language string) (list []string, err error) { - var assetFile string - switch language { - case "de": - assetFile = "lists/frequency.txt" - default: - assetFile = "lists/tothink.txt" +func newWordList(language string, file string) (list []string, err error) { + var asset []byte + if file == "" { + var assetFile string + switch language { + case "de": + assetFile = "lists/frequency.txt" + default: + assetFile = "lists/tothink.txt" + } + asset, err = Asset(assetFile) + if err != nil { + return nil, err + } + } else { + asset, err = ioutil.ReadFile(file) + if err != nil { + return nil, err + } } - asset, err := Asset(assetFile) - if err != nil { - return nil, err - } scanner := bufio.NewScanner(bytes.NewReader(asset)) scanner.Split(bufio.ScanWords) for scanner.Scan() { @@ -49,9 +58,10 @@ func main() { numberOfWords := flag.Uint("n", 3, "number of words") delimeter := flag.String("d", "-", "delimeter as split element for the password") language := flag.String("l", "en", "language of word list: [en, de]") + file := flag.String("f", "", "path to external word list") flag.Parse() - list, err := newWordList(*language) + list, err := newWordList(*language, *file) if err != nil { log.Fatalln(err) }