Esempio n. 1
0
func getPassPhrase(ctx *cli.Context, desc string, confirmation bool, i int) (passphrase string) {
	passfile := ctx.GlobalString(utils.PasswordFileFlag.Name)
	if len(passfile) == 0 {
		fmt.Println(desc)
		auth, err := utils.PromptPassword("Passphrase: ", true)
		if err != nil {
			utils.Fatalf("%v", err)
		}
		if confirmation {
			confirm, err := utils.PromptPassword("Repeat Passphrase: ", false)
			if err != nil {
				utils.Fatalf("%v", err)
			}
			if auth != confirm {
				utils.Fatalf("Passphrases did not match.")
			}
		}
		passphrase = auth

	} else {
		passbytes, err := ioutil.ReadFile(passfile)
		if err != nil {
			utils.Fatalf("Unable to read password file '%s': %v", passfile, err)
		}
		// this is backwards compatible if the same password unlocks several accounts
		// it also has the consequence that trailing newlines will not count as part
		// of the password, so --password <(echo -n 'pass') will now work without -n
		passphrases := strings.Split(string(passbytes), "\n")
		if i >= len(passphrases) {
			passphrase = passphrases[len(passphrases)-1]
		} else {
			passphrase = passphrases[i]
		}
	}
	return
}
Esempio n. 2
0
// askPassword will ask the user to supply the password for a given account
func (self *Jeth) askPassword(id interface{}, jsonrpc string, args []interface{}) bool {
	var err error
	var passwd string
	if len(args) >= 1 {
		if account, ok := args[0].(string); ok {
			fmt.Printf("Unlock account %s\n", account)
			passwd, err = utils.PromptPassword("Passphrase: ", true)
		} else {
			return false
		}
	}

	if err = self.client.Send(shared.NewRpcResponse(id, jsonrpc, passwd, err)); err != nil {
		glog.V(logger.Info).Infof("Unable to send user agent ask password response - %v\n", err)
	}

	return err == nil
}