Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate strong random password #9

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions kaspaperlib/generate_password.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package kaspaperlib
import (
"crypto/rand"
)

func generatePassword() string {
return "password" // TODO: v v v secure random password, nobody ever will guess
func generatePassword() (string, error) {
password := make([]byte, 16)
_, err := rand.Read(password)
if err != nil {
return "", err
}

return string(password), nil
}
5 changes: 4 additions & 1 deletion kaspaperlib/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ func newWallet(dagParams *dagconfig.Params, mnemonic string) (model.KaspaperWall
mnemonicString := &model.MnemonicString{}
copy(mnemonicString[:], strings.Split(mnemonic, " ")) // We assume it splits to 24 words

password := generatePassword()
password, err := generatePassword()
if err != nil {
return nil, err
}

keysFile, err := keys.NewFileFromMnemonic(dagParams, mnemonicString.String(), password)
if err != nil {
Expand Down