public void Test_ResetPassword()
        {
            IMembershipSettings  membershipSettings  = Workmate.Components.InstanceContainer.MembershipSettings;
            IApplicationSettings applicationSettings = Workmate.Components.InstanceContainer.ApplicationSettings;

            WorkmateRoleProvider       roleProvider       = new WorkmateRoleProvider();
            WorkmateMembershipProvider membershipProvider = new WorkmateMembershipProvider();

            string password    = "******";
            string newPassword = "******";

            IUserBasic userBasic = CreateUser(applicationSettings, this.Application, this.DummyDataManager, roleProvider, membershipProvider, password, AccountStatus.Valid);

            IUserBasic         validatedUserBasic;
            ValidateUserStatus validateUserStatus = membershipProvider.ValidateUser(this.Application.ApplicationId, userBasic.Email, password, out validatedUserBasic);

            Assert.AreEqual(ValidateUserStatus.Valid, validateUserStatus);

            ChangePasswordStatus changePasswordStatus = membershipProvider.ResetPassword(this.Application.ApplicationId, userBasic, newPassword);

            Assert.AreEqual(ChangePasswordStatus.Success, changePasswordStatus);

            validateUserStatus = membershipProvider.ValidateUser(this.Application.ApplicationId, userBasic.Email, newPassword, out validatedUserBasic);
            Assert.AreEqual(ValidateUserStatus.Valid, validateUserStatus);
        }
Exemplo n.º 2
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                ChangePasswordStatus status = UserService.ChangePassword(model.CurrentPassword, model.Password);
                switch (status)
                {
                case ChangePasswordStatus.Changed:
                    ShowMessage((L)"Password changed.");
                    return(RedirectToAction("change"));

                case ChangePasswordStatus.InvalidCurrentPassword:
                    ModelState.AddModelError("CurrentPassword", (L)"Invalid current password!");
                    break;

                case ChangePasswordStatus.InsuficientComplexity:
                    ModelState.AddModelError("Password", (L)"Insuficient password complexity!");
                    break;

                case ChangePasswordStatus.NoSuchUser:
                    ShowMessage((L)"No such user account", HtmlMessageType.Error);
                    break;

                case ChangePasswordStatus.NoLocalCredentials:
                    ShowMessage((L)"You don't have local credentials to manage!");
                    break;
                }
            }
            return(Change());
        }
Exemplo n.º 3
0
        public ChangePasswordStatus ChangePassword(String oldPassword, String newPassword)
        {
            String logMethodName = ".ChangePassword(String oldPassword, String newPassword) - ";

            _log.Debug(logMethodName + " - Begin Method");

            MembershipUser user           = GetUser();
            Boolean        changeResponse = false;

            ChangePasswordStatus status = ChangePasswordStatus.Error;

            try
            {
                changeResponse = user.ChangePassword(oldPassword, newPassword);
            }
            catch (Exception ex)
            {
                throw new SecurityAdapterException("An error has occured in the .NET Membership provider while calling MembershipUser.ChangePassword(oldPassword, newPassword)", ex);
            }

            if (changeResponse)
            {
                status = ChangePasswordStatus.Success;
            }
            else
            {
                status = ChangePasswordStatus.Failure;
            }

            _log.Debug(logMethodName + " - End Method");

            return(status);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Altera o password do usuário
        /// </summary>
        /// <param name="userName">usuário</param>
        /// <param name="oldPassword">senha atual</param>
        /// <param name="newPassword">nova senha</param>
        /// <param name="parameters">demais parametros</param>
        /// <returns>resultado da operação</returns>
        public virtual ChangePasswordResult ChangePassword(string userName, string oldPassword, string newPassword, SecurityParameter[] parameters)
        {
            if (ValidatePassword != null)
            {
                PasswordValidateResult validateResult = ValidatePassword.IsValid(newPassword);
                if (!validateResult.IsOk)
                {
                    return(new ChangePasswordResult()
                    {
                        Status = ChangePasswordStatus.Error,
                        Message = validateResult.Message
                    });
                }
            }
            IValidateUserResult authenticateResult = ValidateUser(userName, oldPassword, parameters);

            if ((authenticateResult.Status == AuthenticationStatus.Success) || (authenticateResult.Status == AuthenticationStatus.PasswordWarning) || (authenticateResult.Status == AuthenticationStatus.PasswordExpired))
            {
                if (!_providers.ContainsKey(authenticateResult.User.IdentityProvider))
                {
                    try
                    {
                        _providers.Add(authenticateResult.User.IdentityProvider, Activator.CreateInstance(Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IIdentityProviderManager>().GetProviderByName(authenticateResult.User.IdentityProvider).Type) as IAuthenticate);
                    }
                    catch (Exception ex)
                    {
                        return(new ChangePasswordResult()
                        {
                            Status = ChangePasswordStatus.Error,
                            Message = ex.Message
                        });
                    }
                }
                return(_providers[authenticateResult.User.IdentityProvider].ChangePassword(userName, oldPassword, newPassword, parameters));
            }
            else
            {
                ChangePasswordStatus status = ChangePasswordStatus.Error;
                switch (authenticateResult.Status)
                {
                case AuthenticationStatus.InvalidCaptcha:
                    status = ChangePasswordStatus.InvalidCaptcha;
                    break;

                case AuthenticationStatus.CaptchaRequired:
                    status = ChangePasswordStatus.CaptchaRequired;
                    break;
                }
                return(new ChangePasswordResult()
                {
                    Status = status,
                    Message = authenticateResult.Message,
                    Captcha = authenticateResult.Captcha
                });
            }
        }
Exemplo n.º 5
0
        public void DoChangePassword(string currentPassword, string password, string passwordConfirm)
        {
            ChangePasswordStatus changePassWordStatus = Account.DoChangePassword(this, currentPassword, password, passwordConfirm);

            if (changePassWordStatus == ChangePasswordStatus.SecurityPolitiesDeny)
            {
                throw new Exception("El cambio de contraseña no ha podido ser realizado");
            }
            else if (changePassWordStatus == ChangePasswordStatus.TooShortNewPassword)
            {
                throw new Exception("La nueva contraseña no cumple con el mínimo de 8 caracteres");
            }
            else if (changePassWordStatus == ChangePasswordStatus.WrongConfirmPassword)
            {
                throw new Exception("La nueva contraseña y su confirmación son diferentes");
            }
            else if (changePassWordStatus == ChangePasswordStatus.WrongCurrentPassword)
            {
                throw new Exception("La actual contraseña es erronea");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Change the member's password.
        /// </summary>
        /// <param name="oldPassword">Old Password</param>
        /// <param name="newPassword">New Password - Rules vary on configuration and provider used.</param>
        /// <returns>Status of request directly from the adapter.</returns>
        /// <exception cref="WtfException">Underlying call to the adapter's ChangePassword(oldPassword, newPassword) has failed with an exception</exception>
        public ChangePasswordStatus ChangePassword(string oldPassword, string newPassword)
        {
            String logMethodName = ".ChangePassword(string oldPassword, string newPassword) - ";

            _log.Debug(logMethodName + "Begin Method");

            ChangePasswordStatus status = ChangePasswordStatus.Error;

            try
            {
                _log.Debug(logMethodName + "Calling ISecurityAdapter.ChangePassword(String oldPassword, String newPassword)");
                status = _adapter.ChangePassword(oldPassword, newPassword);
            }
            catch (Exception ex)
            {
                _log.Error(logMethodName + "Error attempting to change the account password", ex);
                throw new WtfException("Error attempting to change the account password", ex);
            }

            _log.Debug(logMethodName + "End Method");
            return(status);
        }