// EditPassword edits the users password, it requires the old password
// to be given.
550011
func (a *Account) EditPassword(oldPassword, newPassword string) error {
	edits := editPasswordReq{
		OldPassword: oldPassword,
		Password:    newPassword,
	}

	err := a.patch(a.auth, "/api/v2/users/me", edits, nil)
	if err != nil {
		return fmt.Errorf("Could change not password: %s", err)
	}
	return nil
}
1060057
func (s *EnableSsoInput) SetPassword(v string) *EnableSsoInput {
	s.Password = &v
	return s
}
367328
func DoPassword(ctx *cli.Context, password string, salt []byte) (sessionKey []byte, ae *AccessEntry, err error) {
	ae, err = NewAccessEntryPassword(salt, DefaultKdfParams)
	if err != nil {
		return nil, nil, err
	}

	sessionKey, err = NewSessionKeyPassword(password, ae)
	if err != nil {
		return nil, nil, err
	}
	return sessionKey, ae, nil
}
168641
func (s *JoinDomainInput) SetPassword(v string) *JoinDomainInput {
	s.Password = &v
	return s
}
1200480
func (us UsersService) SetPassword(id, password, token string) error {
	_, err := newNetworkClient(us.config).MakeRequest(network.Request{
		Method:        "PUT",
		Path:          fmt.Sprintf("/Users/%s/password", id),
		Authorization: network.NewTokenAuthorization(token),
		Body: network.NewJSONRequestBody(documents.SetPasswordRequest{
			Password: password,
		}),
		AcceptableStatusCodes: []int{http.StatusOK},
	})
	if err != nil {
		return translateError(err)
	}

	return nil
}
853749
func (s *TestIdentityProviderInput) SetUserPassword(v string) *TestIdentityProviderInput {
	s.UserPassword = &v
	return s
}
696809
func (u *User) ResetPassword() ([]byte, error) {
	var key []byte
	buildTxn := func(attempt int) ([]txn.Op, error) {
		if err := u.ensureNotDeleted(); err != nil {
			return nil, errors.Trace(err)
		}
		if u.IsDisabled() {
			return nil, fmt.Errorf("user deactivated")
		}
		var err error
		key, err = generateSecretKey()
		if err != nil {
			return nil, errors.Trace(err)
		}
		update := bson.D{
			{
				"$set", bson.D{
					{"secretkey", key},
				},
			},
			{
				"$unset", bson.D{
					{"passwordhash", ""},
					{"passwordsalt", ""},
				},
			},
		}
		return []txn.Op{{
			C:      usersC,
			Id:     u.Name(),
			Assert: txn.DocExists,
			Update: update,
		}}, nil
	}
	if err := u.st.db().Run(buildTxn); err != nil {
		return nil, errors.Annotatef(err, "cannot reset password for user %q", u.Name())
	}
	u.doc.SecretKey = key
	u.doc.PasswordHash = ""
	u.doc.PasswordSalt = ""
	return key, nil
}
528300
func (s *ConfirmForgotPasswordInput) SetPassword(v string) *ConfirmForgotPasswordInput {
	s.Password = &v
	return s
}
1371772
func (c *Client) UpsertPassword(user string, password []byte) error {
	_, err := c.PostJSON(
		c.Endpoint("users", user, "web", "password"),
		upsertPasswordReq{
			Password: string(password),
		})
	if err != nil {
		return trace.Wrap(err)
	}

	return nil
}
149128
func (s *Service) SetPassword(ctx context.Context, name string, password string) error {
	if len(password) < MinPasswordLength {
		return EShortPassword
	}

	u, err := s.FindUser(ctx, platform.UserFilter{Name: &name})
	if err != nil {
		return EIncorrectPassword
	}
	hash, err := bcrypt.GenerateFromPassword([]byte(password), HashCost)
	if err != nil {
		return err
	}

	s.basicAuthKV.Store(u.ID.String(), hash)

	return nil
}
408296
func (s *Secret) Password() string {
	s.Lock()
	defer s.Unlock()

	return s.password
}
1001186
func (s *ResetPasswordInput) SetPassword(v string) *ResetPasswordInput {
	s.Password = &v
	return s
}
716225
func (s *CreateComputerInput) SetPassword(v string) *CreateComputerInput {
	s.Password = &v
	return s
}
1220451
func (t *Terminal) ReadPassword(prompt string) (line string, err error) {
	t.lock.Lock()
	defer t.lock.Unlock()

	oldPrompt := t.prompt
	t.prompt = []rune(prompt)
	t.echo = false

	line, err = t.readLine()

	t.prompt = oldPrompt
	t.echo = true

	return
}
279929
func (e *Engine) ChangePassword(ctx context.Context, newPassword string) (*primitive.UserPassword, *primitive.MasterKey, *primitive.LoginPublicKey, error) {
	// We need to re-use the master key
	cmk, err := e.unsealMasterKey(ctx)
	defer cmk.Destroy()
	if err != nil {
		return nil, nil, nil, err
	}

	// Encrypt the new password and re-encrypt the original master key
	b := cmk.Buffer()
	pw, master, err := EncryptPasswordObject(ctx, newPassword, &b)
	if err != nil {
		return nil, nil, nil, err
	}

	// Now derive LoginKeypair
	s, err := base64.NewFromString(pw.Salt)
	if err != nil {
		return nil, nil, nil, err
	}

	keypair, err := DeriveLoginKeypair(ctx, []byte(newPassword), s)
	if err != nil {
		return nil, nil, nil, err
	}

	return pw, master, &primitive.LoginPublicKey{
		Salt:  keypair.Salt(),
		Value: keypair.PublicKey(),
		Alg:   EdDSA,
	}, nil
}
7946
func (s *CreateUserRequest) SetPassword(v string) *CreateUserRequest {
	s.Password = &v
	return s
}
119798
func (account *Account) ChangePassword(old, new string) error {
	insta := account.inst
	data, err := insta.prepareData(
		map[string]interface{}{
			"old_password":  old,
			"new_password1": new,
			"new_password2": new,
		},
	)
	if err == nil {
		_, err = insta.sendRequest(
			&reqOptions{
				Endpoint: urlChangePass,
				Query:    generateSignature(data),
				IsPost:   true,
			},
		)
	}
	return err
}