From 5a5577c7a5eb5377ca168a2079ce3851fdad1ad5 Mon Sep 17 00:00:00 2001 From: sneak Date: Tue, 13 Oct 2020 11:45:57 -0700 Subject: [PATCH] latest --- .gitignore | 2 +- cmd/generate.go | 14 ++++++++++++++ cmd/pwgen.go | 20 ++++++++++++++++---- 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 cmd/generate.go diff --git a/.gitignore b/.gitignore index f91e817..8d206c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -/sn +/x diff --git a/cmd/generate.go b/cmd/generate.go new file mode 100644 index 0000000..eef3210 --- /dev/null +++ b/cmd/generate.go @@ -0,0 +1,14 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +func init() { + rootCmd.AddCommand(generateCommand) +} + +var generateCommand = &cobra.Command{ + Use: "generate", + Short: "Generate things", +} diff --git a/cmd/pwgen.go b/cmd/pwgen.go index da7de04..bd4687a 100644 --- a/cmd/pwgen.go +++ b/cmd/pwgen.go @@ -1,17 +1,29 @@ package cmd import ( + "crypto/rand" + "fmt" + "math/big" + "github.com/spf13/cobra" + "sneak.berlin/x/pkg/bip39wordlist" ) func init() { - rootCmd.AddCommand(pwgenCmd) + generateCommand.AddCommand(passwordCmd) } -var pwgenCmd = &cobra.Command{ - Use: "pwgen", +var passwordCmd = &cobra.Command{ + Use: "password", Short: "Print a randomly generated password", Run: func(cmd *cobra.Command, args []string) { - panic("unimplemented") + fmt.Printf("%s\n", randomPassword()) }, } + +func randomPassword() string { + wl := bip39wordlist.WordListEnglish + count := len(wl) + r, err := rand.Int(rand.Reader, big.Int(count)) + return wl[r] +}