github.com/decred/politeia@v1.4.0/politeiawww/cmd/shared/userpasswordchange.go (about) 1 // Copyright (c) 2017-2019 The Decred developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 package shared 6 7 import ( 8 "fmt" 9 10 v1 "github.com/decred/politeia/politeiawww/api/www/v1" 11 ) 12 13 // UserPasswordChangeCmd changes the password for the logged in user. 14 type UserPasswordChangeCmd struct { 15 Args struct { 16 Password string `positional-arg-name:"currentPassword"` // Current password 17 NewPassword string `positional-arg-name:"newPassword"` // New password 18 } `positional-args:"true" required:"true"` 19 } 20 21 // Execute executes the change password command. 22 func (cmd *UserPasswordChangeCmd) Execute(args []string) error { 23 // Get password requirements 24 pr, err := client.Policy() 25 if err != nil { 26 return err 27 } 28 29 // Validate new password 30 if uint(len(cmd.Args.NewPassword)) < pr.MinPasswordLength { 31 return fmt.Errorf("password must be %v characters long", 32 pr.MinPasswordLength) 33 } 34 35 // Setup change password request 36 cp := &v1.ChangePassword{ 37 CurrentPassword: DigestSHA3(cmd.Args.Password), 38 NewPassword: DigestSHA3(cmd.Args.NewPassword), 39 } 40 41 // Print request details 42 err = PrintJSON(cp) 43 if err != nil { 44 return err 45 } 46 47 // Send request 48 cpr, err := client.ChangePassword(cp) 49 if err != nil { 50 return err 51 } 52 53 // Print response details 54 return PrintJSON(cpr) 55 } 56 57 // UserPasswordChangeHelpMsg is the output of the help command when 58 // 'userpasswordchange' is specified. 59 const UserPasswordChangeHelpMsg = `userpasswordchange "currentPassword" "newPassword" 60 61 Change password for the currently logged in user. 62 63 Arguments: 64 1. currentPassword (string, required) Current password 65 2. newPassword (string, required) New password`