Exemple #1
0
        /// <summary>
        /// Resets user password.
        /// </summary>
        /// <param name="sender">Source of this event.</param>
        /// <param name="e">Arguments of this event.</param>
        protected void ResetFinalButton_Click(object sender, EventArgs e)
        {
            try
            {
                // Initialize the security provider.
                ISecurityProvider provider = SecurityProviderUtility.CreateProvider(ResetPasswordUsername.Text);

                if (provider.CanResetPassword)
                {
                    // Attempt to reset password.
                    if (provider.ResetPassword(ResetPasswordSecurityAnswer.Text))
                    {
                        // Password reset was successful.
                        ShowMessage("Password reset request has been processed.", false);
                    }
                    else
                    {
                        // Show why password reset failed.
                        if (!ShowFailureReason(provider))
                        {
                            ShowMessage("Password reset was not successful.", true);
                        }
                    }
                }
                else
                {
                    // Resetting password is not supported.
                    ShowMessage("Account does not support password reset.", true);
                }
            }
            catch (SecurityException ex)
            {
                // Show security related error messages.
                ShowMessage(ex.Message.EnsureEnd('.'), true);
            }
            catch (Exception ex)
            {
                // Show ambiguous message for other errors.
                ShowMessage("Password reset failed due to an unexpected error.", true);
                System.Diagnostics.Trace.WriteLine(string.Format("Password reset error: \r\n  {0}", ex));
            }
            finally
            {
                ResetPasswordSecurityAnswer.Focus();
            }
        }