// * Check if user passphrase matches argument. Launches SecretUI prompt if
// * passphrase argument is empty. Returns `true` if passphrase is correct,
// * false if not, or an error if something else went wrong.
2157
func (c AccountClient) PassphraseCheck(ctx context.Context, __arg PassphraseCheckArg) (res bool, err error) {
	err = c.Cli.Call(ctx, "keybase.1.account.passphraseCheck", []interface{}{__arg}, &res)
	return
}
526267
func (e *loginProvision) checkArg() error {
	// check we have a good device type:
	if e.arg.DeviceType != libkb.DeviceTypeDesktop && e.arg.DeviceType != libkb.DeviceTypeMobile {
		return libkb.InvalidArgumentError{Msg: fmt.Sprintf("device type must be %q or %q, not %q", libkb.DeviceTypeDesktop, libkb.DeviceTypeMobile, e.arg.DeviceType)}
	}

	if e.arg.User == nil {
		return libkb.InvalidArgumentError{Msg: "User cannot be nil"}
	}

	return nil
}
592791
func promptForConfirmation(msg string) bool {
	reader := bufio.NewReader(os.Stdin)

	for {
		fmt.Print(msg)

		answer, err := reader.ReadString('\n')
		if err != nil {
			return false
		}

		answer = strings.ToLower(strings.TrimSpace(answer))

		switch {
		case answer == "yes":
			return true
		case answer == "no":
			return false
		default:
			continue
		}
	}
}
423644
func usernamePrompt(conn connector.PasswordConnector) string {
	if attr := conn.Prompt(); attr != "" {
		return attr
	}
	return "Username"
}
167607
func (a *SimpleAuth) CheckPasswd(name, pass string) (bool, error) {
	if name != a.Name || pass != a.Password {
		return false, nil
	}
	return true, nil
}
815260
func (ks *KeyStore) SignHashPassphrase(account *Account, passphrase string, hash []byte) (signature []byte, _ error) {
	return ks.keystore.SignHashWithPassphrase(account.account, passphrase, common.CopyBytes(hash))
}
1147184
func assertNotExists(p string) []error {
	var errs []error
	e, err := fileExists(p)
	if err != nil {
		errs = append(errs, fmt.Errorf("error checking %q exists: %v", p, err))
	}
	if e {
		errs = append(errs, fmt.Errorf("file %q exists unexpectedly", p))
	}
	return errs
}
611278
func walletPassphrase(icmd interface{}, w *wallet.Wallet) (interface{}, error) {
	cmd := icmd.(*btcjson.WalletPassphraseCmd)

	timeout := time.Second * time.Duration(cmd.Timeout)
	var unlockAfter <-chan time.Time
	if timeout != 0 {
		unlockAfter = time.After(timeout)
	}
	err := w.Unlock([]byte(cmd.Passphrase), unlockAfter)
	return nil, err
}
947916
func (a *AskPassCredentialHelper) args(prompt string) []string {
	if len(prompt) == 0 {
		return nil
	}
	return []string{prompt}
}
355585
func (c *PassphraseCheck) Run(mctx libkb.MetaContext) (err error) {
	defer mctx.Trace("PassphraseCheck#Run", func() error { return err })()

	passphrase := c.arg.Passphrase
	if passphrase == "" {
		username := c.G().GetEnv().GetUsername().String()
		promptArg := libkb.DefaultPassphrasePromptArg(mctx, username)
		if !mctx.UIs().HasUI(libkb.SecretUIKind) {
			return errors.New("Passphrase was not passed in arguments and SecretUI is not available")
		}
		res, err := mctx.UIs().SecretUI.GetPassphrase(promptArg, nil)
		if err != nil {
			return err
		}
		passphrase = res.Passphrase
	}

	_, err = libkb.VerifyPassphraseForLoggedInUser(mctx, passphrase)
	if err != nil {
		if _, ok := err.(libkb.PassphraseError); ok {
			// Swallow passphrase errors, return `false` that the passphrase
			// provided was incorrect.
			c.result = false
			return nil
		}
		// There was some other error.
		return err
	}
	// No error, passphrase was correct.
	c.result = true
	return nil
}
77789
func passwordPrompt() string {
	fmt.Print("Enter password: ")
	password, errs := terminal.ReadPassword(0)

	if errs != nil {
		fmt.Println("\nCould not read password:")
		log.Fatal(errs)
		os.Exit(1)
	}

	fmt.Print("\nConfirm password: ")
	passwordConfirm, errs := terminal.ReadPassword(0)

	if errs != nil {
		fmt.Println("\nCould Not read password.")
		log.Fatal(errs)
		os.Exit(1)
	}

	if reflect.DeepEqual(password, passwordConfirm) == false {
		fmt.Println()
		log.Fatal("Passwords do not match")
	}

	return strings.TrimSpace(string(password))
}
1234072
func GetPassphrase(in *bufio.Reader) ([]byte, error) {
	var (
		passphrase []byte
		err        error
	)

	if terminal.IsTerminal(int(os.Stdin.Fd())) {
		passphrase, err = terminal.ReadPassword(int(os.Stdin.Fd()))
	} else {
		passphrase, err = in.ReadBytes('\n')
	}

	return passphrase, err
}
277532
func NewMatchPhraseQuery(phrase string) *MatchPhraseQuery {
	q := &MatchPhraseQuery{newFtsQueryBase()}
	q.options["match_phrase"] = phrase
	return q
}
15548
func (f *CLI) prompt() {
	defer fmt.Println(f.action() + "ing...")
	if f.yes {
		return
	}
	fmt.Printf("%s completion for %s? ", f.action(), f.Name)
	var answer string
	fmt.Scanln(&answer)

	switch strings.ToLower(answer) {
	case "y", "yes":
		return
	default:
		fmt.Println("Cancelling...")
		os.Exit(1)
	}
}
1359804
func GetPassphraseStreamViaPrompt(m MetaContext) (pps *PassphraseStream, tsec Triplesec, err error) {

	// We have to get the current username before we install the new provisional login context,
	// which will shadow the logged in username.
	nun := m.CurrentUsername()
	defer m.Trace(fmt.Sprintf("GetPassphraseStreamViaPrompt(%s)", nun), func() error { return err })()

	m = m.WithNewProvisionalLoginContext()
	err = PassphraseLoginPromptThenSecretStore(m, nun.String(), 5, false /* failOnStoreError */)
	if err != nil {
		return nil, nil, err
	}
	pps, tsec = m.PassphraseStreamAndTriplesec()
	m.CommitProvisionalLogin()

	return pps, tsec, nil
}
570217
func (md *Metadata) PasscodePrompt() string {
	// Give default in case server doesn't tell us
	if len(md.Prompts.Passcode) == 2 && md.Prompts.Passcode[1] != "" {
		return md.Prompts.Passcode[1]
	}
	var loginURL string
	if md.Links.Login != "" {
		loginURL = md.Links.Login
	} else {
		loginURL = "https://login.system.example.com"
	}
	return fmt.Sprintf("One Time Code ( Get one at %s/passcode )", loginURL)
}
574261
func (ui *UI) DisplayPasswordPrompt(template string, templateValues ...map[string]interface{}) (string, error) {
	ui.terminalLock.Lock()
	defer ui.terminalLock.Unlock()

	var password interact.Password
	interactivePrompt := ui.Interactor.NewInteraction(ui.TranslateText(template, templateValues...))
	interactivePrompt.SetIn(ui.In)
	interactivePrompt.SetOut(ui.OutForInteration)
	err := interactivePrompt.Resolve(interact.Required(&password))
	if isInterrupt(err) {
		ui.Exiter.Exit(sigIntExitCode)
	}
	return string(password), err
}