Skip to content

Commit

Permalink
fix: add safe notice to user
Browse files Browse the repository at this point in the history
  • Loading branch information
flywukong committed Oct 11, 2023
1 parent 3443acb commit ab25f77
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions cmd/cmd_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,11 @@ func importKey(ctx *cli.Context) error {
}

// fetch password content
password, err = getPassword(ctx)
password, err = getPassword(ctx, true)
if err != nil {
return toCmdErr(err)
}
fmt.Println("- You must REMEMBER your password! Without the password, it's impossible to decrypt the key!")

// encrypt the private key
encryptContent, err = EncryptKey(key, password, EncryptScryptN, EncryptScryptP)
Expand Down Expand Up @@ -391,7 +392,7 @@ func createAccount(ctx *cli.Context) error {
}

// fetch password content
password, err = getPassword(ctx)
password, err = getPassword(ctx, true)
if err != nil {
return toCmdErr(err)
}
Expand Down Expand Up @@ -524,7 +525,7 @@ func parseKeystore(ctx *cli.Context) (string, string, error) {
return "", "", toCmdErr(err)
}
// fetch password content
password, err := getPassword(ctx)
password, err := getPassword(ctx, false)
if err != nil {
return "", "", toCmdErr(err)
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func parseActions(ctx *cli.Context, resourceType ResourceType) ([]permTypes.Acti
}

// getPassword return the password content
func getPassword(ctx *cli.Context) (string, error) {
func getPassword(ctx *cli.Context, needNotice bool) (string, error) {
var filepath string
if passwordFile := ctx.String(passwordFileFlag); passwordFile != "" {
filepath = passwordFile
Expand All @@ -350,13 +350,18 @@ func getPassword(ctx *cli.Context) (string, error) {
}

fmt.Print("Please enter the passphrase now:")

bytePassword, err := term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
fmt.Println("read password err:", err)
return "", err
}
password := string(bytePassword)
fmt.Println()
if needNotice {
fmt.Println("- You must BACKUP your key file! Without the key, it's impossible to set transaction to greenfield!")
fmt.Println("- You must REMEMBER your password! Without the password, it's impossible to decrypt the key!")
}
return password, nil
}

Expand Down

0 comments on commit ab25f77

Please sign in to comment.