// EditPassword check user password and overwrite it with a new one
506074
func (s *service) EditPassword(reqDTO rest.RequestDTOPutPassword) (resDTO rest.ResponseDTO, error *servicehelper.Error) {
	entity, err := s.repo.FindByEmail(reqDTO.Email)
	if err != nil {
		return rest.ResponseDTO{}, &servicehelper.Error{
			Detail:  errors.New("user could not be found"),
			Message: "We could not find any user with the provided email address",
			Param:   "email",
			Code:    servicehelper.NotFound,
		}
	}

	if scrypt.CompareHashAndPassword([]byte(entity.Password), []byte(reqDTO.Password)) != nil {
		return rest.ResponseDTO{}, &servicehelper.Error{
			Detail:  errors.New("invalid password"),
			Message: "We could not authenticate you, please type you password again",
			Param:   "password",
			Code:    servicehelper.BadRequest,
		}
	}

	hashedPassword, err := scrypt.GenerateFromPassword([]byte(reqDTO.NewPassword), scrypt.DefaultParams)
	if err != nil {
		return rest.ResponseDTO{}, &servicehelper.Error{
			Detail:  errors.New("could not hash the password"),
			Message: "We could not create your password, please try something different",
			Param:   "password",
			Code:    servicehelper.UnexpectedError,
		}
	}
	entity.Password = string(hashedPassword[:])

	if err := s.repo.Update(entity); err != nil {
		return rest.ResponseDTO{}, &servicehelper.Error{
			Detail:  errors.New("could not update user"),
			Message: "We could not update the password of this account, please contact us or try again later",
			Code:    servicehelper.UnexpectedError}
	}

	return createDTOFromEntity(entity), error
}
1331960
func (s *IngestEndpoint) SetPassword(v string) *IngestEndpoint {
	s.Password = &v
	return s
}
146193
func (s *RedshiftDestinationUpdate) SetPassword(v string) *RedshiftDestinationUpdate {
	s.Password = &v
	return s
}
810310
func Password(prefix string) (string, error) {
	term, err := NewTerminal()
	if err != nil {
		return "", err
	}
	defer term.Close()

	return term.Password(prefix)
}
1241558
func (state *UserState) SetPassword(username, password string) {
	state.users.Set(username, "password", state.HashPassword(username, password))
}
685206
func (s *UsersService) UpdatePassword(username string, body UsersUsernamePasswordPutReqBody, headers, queryParams map[string]interface{}) (*http.Response, error) {
	var err error

	resp, err := s.client.doReqWithBody("PUT", s.client.BaseURI+"/users/"+username+"/password", &body, headers, queryParams)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	switch resp.StatusCode {
	case 422:
		var respBody422 Error
		err = goraml.NewAPIError(resp, &respBody422)
	default:
		err = goraml.NewAPIError(resp, nil)
	}

	return resp, err
}
763667
func (s *IdentityService) UpsertPassword(user string, password []byte) error {
	if user == "" {
		return trace.BadParameter("missing username")
	}
	err := services.VerifyPassword(password)
	if err != nil {
		return trace.Wrap(err)
	}
	hash, err := bcrypt.GenerateFromPassword(password, bcrypt.DefaultCost)
	if err != nil {
		return trace.Wrap(err)
	}

	err = s.UpsertPasswordHash(user, hash)
	if err != nil {
		return trace.Wrap(err)
	}

	return nil
}
749866
func (state *UserState) CorrectPassword(username, password string) bool {

	if !state.HasUser(username) {
		return false
	}

	// Retrieve the stored password hash
	hash := state.storedHash(username)
	if len(hash) == 0 {
		return false
	}

	// Check the password with the right password algorithm
	switch state.passwordAlgorithm {
	case "sha256":
		return correctSha256(hash, state.cookieSecret, username, password)
	case "bcrypt":
		return correctBcrypt(hash, password)
	case "bcrypt+": // for backwards compatibility with sha256
		if isSha256(hash) && correctSha256(hash, state.cookieSecret, username, password) {
			return true
		}
		return correctBcrypt(hash, password)
	}
	return false
}
982229
func CheckPassword(password, encoded string) (bool, error) {
	if !IsPasswordUsable(encoded) {
		return false, nil
	}

	hasher := IdentifyHasher(encoded)

	if !IsValidHasher(hasher) {
		return false, ErrInvalidHasher
	}

	if !IsHasherImplemented(hasher) {
		return false, ErrHasherNotImplemented
	}

	switch hasher {
	case Argon2Hasher:
		return argon2.NewArgon2Hasher().Verify(password, encoded)
	case BCryptHasher:
		return bcrypt.NewBCryptHasher().Verify(password, encoded)
	case BCryptSHA256Hasher:
		return bcrypt.NewBCryptSHA256Hasher().Verify(password, encoded)
	case PBKDF2SHA1Hasher:
		return pbkdf2.NewPBKDF2SHA1Hasher().Verify(password, encoded)
	case PBKDF2SHA256Hasher:
		return pbkdf2.NewPBKDF2SHA256Hasher().Verify(password, encoded)
	}

	return false, ErrInvalidHasher
}
937118
func (s *RedshiftSettings) SetPassword(v string) *RedshiftSettings {
	s.Password = &v
	return s
}
657368
func (s *PasswordsService) SetPassword(ctx context.Context, name string, password string) error {
	return s.SetPasswordFn(ctx, name, password)
}
6878
func (s *CreateEndpointInput) SetPassword(v string) *CreateEndpointInput {
	s.Password = &v
	return s
}
994218
func Password(confirm bool, override *string) (string, error) {
	preferences, err := prefs.NewPreferences()
	if err != nil {
		return "", err
	}

	label := "Password"
	if override != nil {
		label = *override
	}

	if !ui.Attached() {
		return "", errs.ErrTerminalRequired
	}

	prompt := &promptui.Prompt{
		Label:     label,
		Mask:      pwMask,
		Validate:  promptui.ValidateFunc(validate.Password),
		IsVimMode: preferences.Core.Vim,
	}

	password, err := prompt.Run()
	if err != nil {
		return "", err
	}

	if !confirm {
		return password, err
	}

	prompt = &promptui.Prompt{
		Label:     "Confirm " + label,
		Mask:      pwMask,
		Validate:  promptui.ValidateFunc(validate.ConfirmPassword(password)),
		IsVimMode: preferences.Core.Vim,
	}

	_, err = prompt.Run()
	if err != nil {
		return "", convertErr(err)
	}

	return password, nil
}
388682
func (auth *Auth) ByPassword(email, password string) (user User, err error) {
	// Get the user by email - emails MUST be unique
	if user, err = auth.users.GetByEmail(email); err != nil {
		user = User{} // Do not leak user information
		return
	}

	// Check the cleartext versus encrypted password
	if !CheckPassword(auth.users.Hasher(), password, user.Password) {
		user = User{} // Do not leak user information
		err = fmt.Errorf("auth: incorrect password for user %s", user.Email)
	}
	return
}
549827
func (s *CreateMicrosoftADInput) SetPassword(v string) *CreateMicrosoftADInput {
	s.Password = &v
	return s
}
528300
func (s *ConfirmForgotPasswordInput) SetPassword(v string) *ConfirmForgotPasswordInput {
	s.Password = &v
	return s
}
288379
func SetPassword(file, name, password string, hashAlgorithm HashAlgorithm) error {
	_, err := os.Stat(file)
	passwords := HashedPasswords(map[string]string{})
	if err == nil {
		passwords, err = ParseHtpasswdFile(file)
		if err != nil {
			return err
		}
	}
	err = passwords.SetPassword(name, password, hashAlgorithm)
	if err != nil {
		return err
	}
	return passwords.WriteToFile(file)
}