forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwgen.go
28 lines (24 loc) · 855 Bytes
/
pwgen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package xkcdgen
import "github.com/martinhoefling/goxkcdpwgen/xkcdpwgen"
// Random returns a random passphrase combined from four words
func Random() string {
password, _ := RandomLength(4, "en")
return password
}
// RandomLength returns a random passphrase combined from the desired number
// of words
func RandomLength(length int, lang string) (string, error) {
return RandomLengthDelim(length, " ", lang)
}
// RandomLengthDelim returns a random passphrase combined from the desired number
// of words and the given delimiter. Words are drawn from lang
func RandomLengthDelim(length int, delim, lang string) (string, error) {
g := xkcdpwgen.NewGenerator()
g.SetNumWords(length)
g.SetDelimiter(delim)
g.SetCapitalize(delim == "")
if err := g.UseLangWordlist(lang); err != nil {
return "", err
}
return string(g.GeneratePassword()), nil
}