add password generator

This commit is contained in:
2025-03-07 12:33:40 -05:00
parent 116be25489
commit 0d386e2d9f
27 changed files with 17895 additions and 42 deletions

13
generator/passphrase.go Normal file
View 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
View 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
}