github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/client/keys/update.go (about) 1 package keys 2 3 import ( 4 "bufio" 5 6 "github.com/spf13/cobra" 7 "github.com/spf13/viper" 8 9 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/flags" 10 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/input" 11 ) 12 13 // UpdateKeyCommand changes the password of a key in the keybase. 14 // It takes no effect on keys managed by new the keyring-based keybase implementation. 15 func UpdateKeyCommand() *cobra.Command { 16 cmd := &cobra.Command{ 17 Use: "update <name>", 18 Short: "Change the password used to protect private key", 19 Deprecated: `it takes no effect with the new keyring 20 based backend and is provided only for backward compatibility with the 21 legacy LevelDB based backend. 22 Refer to your operating system's manual to learn how to change your 23 keyring's password. 24 `, 25 RunE: runUpdateCmd, 26 Args: cobra.ExactArgs(1), 27 } 28 return cmd 29 } 30 31 func runUpdateCmd(cmd *cobra.Command, args []string) error { 32 name := args[0] 33 34 buf := bufio.NewReader(cmd.InOrStdin()) 35 kb, err := NewKeyBaseFromDir(viper.GetString(flags.FlagHome)) 36 if err != nil { 37 return err 38 } 39 oldpass, err := input.GetPassword("Enter the current passphrase:", buf) 40 if err != nil { 41 return err 42 } 43 44 getNewpass := func() (string, error) { 45 return input.GetCheckPassword( 46 "Enter the new passphrase:", 47 "Repeat the new passphrase:", buf) 48 } 49 if err := kb.Update(name, oldpass, getNewpass); err != nil { 50 return err 51 } 52 53 cmd.PrintErrln("Password successfully updated!") 54 return nil 55 }