cmd: replace passPHRASE with passWORD in any user interactions #19932 (#1535)

This commit is contained in:
Daniel Liu 2025-09-21 19:31:00 +08:00 committed by GitHub
parent 8615067df1
commit 22dc136ffe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 54 additions and 59 deletions

View file

@ -117,11 +117,11 @@ Print a short summary of all accounts`,
Creates a new account and prints the address.
The account is saved in encrypted format, you are prompted for a passphrase.
The account is saved in encrypted format, you are prompted for a password.
You must remember this passphrase to unlock your account in the future.
You must remember this password to unlock your account in the future.
For non-interactive use the passphrase can be specified with the --password flag:
For non-interactive use the password can be specified with the --password flag:
Note, this is meant to be used for testing only, it is a bad idea to save your
password to file or expose in any other way.
@ -144,12 +144,12 @@ password to file or expose in any other way.
Update an existing account.
The account is saved in the newest version in encrypted format, you are prompted
for a passphrase to unlock the account and another to save the updated file.
for a password to unlock the account and another to save the updated file.
This same command can therefore be used to migrate an account of a deprecated
format to the newest format or change the password for an account.
For non-interactive use the passphrase can be specified with the --password flag:
For non-interactive use the password can be specified with the --password flag:
XDC account update [options] <address>
@ -177,11 +177,11 @@ Prints the address.
The keyfile is assumed to contain an unencrypted private key in hexadecimal format.
The account is saved in encrypted format, you are prompted for a passphrase.
The account is saved in encrypted format, you are prompted for a password.
You must remember this passphrase to unlock your account in the future.
You must remember this password to unlock your account in the future.
For non-interactive use the passphrase can be specified with the -password flag:
For non-interactive use the password can be specified with the -password flag:
XDC account import [options] <keyfile>
@ -268,17 +268,17 @@ func getPassPhrase(prompt string, confirmation bool, i int, passwords []string)
if prompt != "" {
fmt.Println(prompt)
}
password, err := prompt2.Stdin.PromptPassword("Passphrase: ")
password, err := prompt2.Stdin.PromptPassword("Password: ")
if err != nil {
utils.Fatalf("Failed to read passphrase: %v", err)
utils.Fatalf("Failed to read password: %v", err)
}
if confirmation {
confirm, err := prompt2.Stdin.PromptPassword("Repeat passphrase: ")
confirm, err := prompt2.Stdin.PromptPassword("Repeat password: ")
if err != nil {
utils.Fatalf("Failed to read passphrase confirmation: %v", err)
utils.Fatalf("Failed to read password confirmation: %v", err)
}
if password != confirm {
utils.Fatalf("Passphrases do not match")
utils.Fatalf("Passwords do not match")
}
}
return password
@ -289,7 +289,7 @@ func ambiguousAddrRecovery(ks *keystore.KeyStore, err *keystore.AmbiguousAddrErr
for _, a := range err.Matches {
fmt.Println(" ", a.URL)
}
fmt.Println("Testing your passphrase against all of them...")
fmt.Println("Testing your password against all of them...")
var match *accounts.Account
for _, a := range err.Matches {
if err := ks.Unlock(a, auth); err == nil {
@ -300,7 +300,7 @@ func ambiguousAddrRecovery(ks *keystore.KeyStore, err *keystore.AmbiguousAddrErr
if match == nil {
utils.Fatalf("None of the listed files could be unlocked.")
}
fmt.Printf("Your passphrase unlocked %s\n", match.URL)
fmt.Printf("Your password unlocked %s\n", match.URL)
fmt.Println("In order to avoid this warning, you need to remove the following duplicate key files:")
for _, a := range err.Matches {
if a != *match {

View file

@ -76,8 +76,8 @@ func TestAccountNew(t *testing.T) {
XDC.Expect(`
Your new account is locked with a password. Please give a password. Do not forget this password.
!! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "foobar"}}
Repeat passphrase: {{.InputLine "foobar"}}
Password: {{.InputLine "foobar"}}
Repeat password: {{.InputLine "foobar"}}
Your new key was generated
@ -121,9 +121,9 @@ func TestAccountNewBadRepeat(t *testing.T) {
XDC.Expect(`
Your new account is locked with a password. Please give a password. Do not forget this password.
!! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "something"}}
Repeat passphrase: {{.InputLine "something else"}}
Fatal: Passphrases do not match
Password: {{.InputLine "something"}}
Repeat password: {{.InputLine "something else"}}
Fatal: Passwords do not match
`)
}
@ -135,10 +135,10 @@ func TestAccountUpdate(t *testing.T) {
XDC.Expect(`
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
!! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "foobar"}}
Password: {{.InputLine "foobar"}}
Please give a new password. Do not forget this password.
Passphrase: {{.InputLine "foobar2"}}
Repeat passphrase: {{.InputLine "foobar2"}}
Password: {{.InputLine "foobar2"}}
Repeat password: {{.InputLine "foobar2"}}
`)
}
@ -148,7 +148,7 @@ func TestWalletImport(t *testing.T) {
defer XDC.ExpectExit()
XDC.Expect(`
!! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "foo"}}
Password: {{.InputLine "foo"}}
Address: {xdcd4584b5f6229b7be90727b0fc8c6b91bb427821f}
`)
@ -193,7 +193,7 @@ func TestWalletImportBadPassword(t *testing.T) {
defer XDC.ExpectExit()
XDC.Expect(`
!! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "wrong"}}
Password: {{.InputLine "wrong"}}
Fatal: could not decrypt key with given password
`)
}
@ -208,7 +208,7 @@ func TestUnlockFlag(t *testing.T) {
XDC.Expect(`
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
!! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "foobar"}}
Password: {{.InputLine "foobar"}}
`)
XDC.ExpectExit()
@ -233,11 +233,11 @@ func TestUnlockFlagWrongPassword(t *testing.T) {
XDC.Expect(`
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
!! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "wrong1"}}
Password: {{.InputLine "wrong1"}}
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 2/3
Passphrase: {{.InputLine "wrong2"}}
Password: {{.InputLine "wrong2"}}
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 3/3
Passphrase: {{.InputLine "wrong3"}}
Password: {{.InputLine "wrong3"}}
Fatal: Failed to unlock account f466859ead1932d743d622cb74fc058882e8648a (could not decrypt key with given password)
`)
}
@ -252,9 +252,9 @@ func TestUnlockFlagMultiIndex(t *testing.T) {
XDC.Expect(`
Unlocking account 0 | Attempt 1/3
!! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "foobar"}}
Password: {{.InputLine "foobar"}}
Unlocking account 2 | Attempt 1/3
Passphrase: {{.InputLine "foobar"}}
Password: {{.InputLine "foobar"}}
`)
XDC.ExpectExit()
@ -319,12 +319,12 @@ func TestUnlockFlagAmbiguous(t *testing.T) {
XDC.Expect(`
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
!! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "foobar"}}
Password: {{.InputLine "foobar"}}
Multiple key files exist for address f466859ead1932d743d622cb74fc058882e8648a:
keystore://{{keypath "1"}}
keystore://{{keypath "2"}}
Testing your passphrase against all of them...
Your passphrase unlocked keystore://{{keypath "1"}}
Testing your password against all of them...
Your password unlocked keystore://{{keypath "1"}}
In order to avoid this warning, you need to remove the following duplicate key files:
keystore://{{keypath "2"}}
`)
@ -356,11 +356,11 @@ func TestUnlockFlagAmbiguousWrongPassword(t *testing.T) {
XDC.Expect(`
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
!! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "wrong"}}
Password: {{.InputLine "wrong"}}
Multiple key files exist for address f466859ead1932d743d622cb74fc058882e8648a:
keystore://{{keypath "1"}}
keystore://{{keypath "2"}}
Testing your passphrase against all of them...
Testing your password against all of them...
Fatal: None of the listed files could be unlocked.
`)
XDC.ExpectExit()

View file

@ -3,39 +3,34 @@ ethkey
ethkey is a simple command-line tool for working with Ethereum keyfiles.
# Usage
### `ethkey generate`
Generate a new keyfile.
If you want to use an existing private key to use in the keyfile, it can be
specified by setting `--privatekey` with the location of the file containing the
If you want to use an existing private key to use in the keyfile, it can be
specified by setting `--privatekey` with the location of the file containing the
private key.
### `ethkey inspect <keyfile>`
Print various information about the keyfile.
Private key information can be printed by using the `--private` flag;
make sure to use this feature with great caution!
### `ethkey sign <keyfile> <message/file>`
Sign the message with a keyfile.
It is possible to refer to a file containing the message.
### `ethkey verify <address> <signature> <message/file>`
Verify the signature of the message.
It is possible to refer to a file containing the message.
## Passwords
## Passphrases
For every command that uses a keyfile, you will be prompted to provide the
passphrase for decrypting the keyfile. To avoid this message, it is possible
to pass the passphrase by using the `--passphrase` flag pointing to a file that
contains the passphrase.
For every command that uses a keyfile, you will be prompted to provide the
password for decrypting the keyfile. To avoid this message, it is possible
to pass the password by using the `--passwordfile` flag pointing to a file that
contains the password.

View file

@ -31,8 +31,8 @@ func TestMessageSignVerify(t *testing.T) {
generate := runEthkey(t, "generate", keyfile)
generate.Expect(`
!! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "foobar"}}
Repeat passphrase: {{.InputLine "foobar"}}
Password: {{.InputLine "foobar"}}
Repeat password: {{.InputLine "foobar"}}
`)
_, matches := generate.ExpectRegexp(`Address: (xdc[0-9a-fA-F]{40})\n`)
address := matches[1]
@ -42,7 +42,7 @@ Repeat passphrase: {{.InputLine "foobar"}}
sign := runEthkey(t, "signmessage", keyfile, message)
sign.Expect(`
!! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "foobar"}}
Password: {{.InputLine "foobar"}}
`)
_, matches = sign.ExpectRegexp(`Signature: ([0-9a-f]+)\n`)
signature := matches[1]

View file

@ -29,32 +29,32 @@ import (
)
// getPassPhrase obtains a passphrase given by the user. It first checks the
// --passphrase command line flag and ultimately prompts the user for a
// --passfile command line flag and ultimately prompts the user for a
// passphrase.
func getPassPhrase(ctx *cli.Context, confirmation bool) string {
// Look for the --passphrase flag.
// Look for the --passwordfile flag.
passphraseFile := ctx.String(passphraseFlag.Name)
if passphraseFile != "" {
content, err := os.ReadFile(passphraseFile)
if err != nil {
utils.Fatalf("Failed to read passphrase file '%s': %v",
utils.Fatalf("Failed to read password file '%s': %v",
passphraseFile, err)
}
return strings.TrimRight(string(content), "\r\n")
}
// Otherwise prompt the user for the passphrase.
passphrase, err := prompt.Stdin.PromptPassword("Passphrase: ")
passphrase, err := prompt.Stdin.PromptPassword("Password: ")
if err != nil {
utils.Fatalf("Failed to read passphrase: %v", err)
utils.Fatalf("Failed to read password: %v", err)
}
if confirmation {
confirm, err := prompt.Stdin.PromptPassword("Repeat passphrase: ")
confirm, err := prompt.Stdin.PromptPassword("Repeat password: ")
if err != nil {
utils.Fatalf("Failed to read passphrase confirmation: %v", err)
utils.Fatalf("Failed to read password confirmation: %v", err)
}
if passphrase != confirm {
utils.Fatalf("Passphrases do not match")
utils.Fatalf("Passwords do not match")
}
}
return passphrase