예제 #1
0
        public bool ResetPassword(ResetPasswordParameters parameters)
        {
            if (parameters == null)
            {
                throw new ClientException("It is not allowed to call this authentication service method with no parameters provided.");
            }
            _logger.Trace("ResetPassword");
            parameters.Validate();
            CheckPasswordStrength(parameters.NewPassword);

            int userId = WebSecurity.GetUserIdFromPasswordResetToken(parameters.PasswordResetToken);
            SimpleMembershipProvider provider = (SimpleMembershipProvider)Membership.Provider;
            string userName = provider.GetUserNameFromId(userId);

            _logger.Trace(() => "ResetPassword " + userName);

            bool successfulReset = SafeExecute(
                () => WebSecurity.ResetPassword(parameters.PasswordResetToken, parameters.NewPassword),
                "ResetPassword", userName);

            if (successfulReset && !string.IsNullOrEmpty(userName))
            {
                SafeExecute( // Login does not need to be successful for this function to return true.
                    () => { Login(new LoginParameters {
                        UserName = userName, Password = parameters.NewPassword, PersistCookie = false
                    }); },
                    "Login after ResetPassword", userName);
            }

            return(successfulReset);
        }
예제 #2
0
        public bool ResetPassword(ResetPasswordParameters parameters)
        {
            if (parameters == null)
                throw new ClientException("It is not allowed to call this authentication service method with no parameters provided.");
            _logger.Trace("ResetPassword");
            parameters.Validate();
            CheckPasswordStrength(parameters.NewPassword);

            int userId = WebSecurity.GetUserIdFromPasswordResetToken(parameters.PasswordResetToken);
            SimpleMembershipProvider provider = (SimpleMembershipProvider)Membership.Provider;
            string userName = provider.GetUserNameFromId(userId);
            _logger.Trace(() => "ResetPassword " + userName);

            bool successfulReset = SafeExecute(
                () => WebSecurity.ResetPassword(parameters.PasswordResetToken, parameters.NewPassword),
                "ResetPassword", userName);

            if (successfulReset && !string.IsNullOrEmpty(userName))
                SafeExecute( // Login does not need to be successful for this function to return true.
                    () => { Login(new LoginParameters { UserName = userName, Password = parameters.NewPassword, PersistCookie = false }); },
                    "Login after ResetPassword", userName);

            return successfulReset;
        }
예제 #3
0
 public async Task <bool> ResetPassword([FromBody] ResetPasswordParameters parameters)
 {
     ValidateForEmptyParameters(parameters);
     return(await _authenticationService.ResetPasswordAsync(parameters.UserName, parameters.NewPassword, parameters.PasswordResetToken));
 }