add password generator
This commit is contained in:
13
generator/passphrase.go
Normal file
13
generator/passphrase.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package generator
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/sethvargo/go-diceware/diceware"
|
||||
)
|
||||
|
||||
func GeneratePassphrase(words int) string {
|
||||
list, _ := diceware.Generate(words)
|
||||
|
||||
return strings.Join(list, " ")
|
||||
}
|
||||
26
generator/password.go
Normal file
26
generator/password.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package generator
|
||||
|
||||
import "github.com/sethvargo/go-password/password"
|
||||
|
||||
func GeneratePassword(length int, digits int, symbols int, disableUpper bool, allowRepeats bool) string {
|
||||
if length <= 0 {
|
||||
length = 16
|
||||
}
|
||||
|
||||
if digits <= 0 {
|
||||
digits = 0
|
||||
}
|
||||
|
||||
if symbols <= 0 {
|
||||
symbols = 0
|
||||
}
|
||||
|
||||
result, _ := password.Generate(length, digits, symbols, disableUpper, allowRepeats)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func GenerateDefault() string {
|
||||
result, _ := password.Generate(24, 5, 5, false, false)
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user