Ejemplo n.º 1
0
        /// <summary>
        /// Displays requested screen section based on received request.
        /// </summary>
        private void ManageScreenVisualization()
        {
            // Initially hide everything on all screens
            LoginSection.Visibility          = Visibility.Collapsed;
            AccessDeniedSection.Visibility   = Visibility.Collapsed;
            ChangePasswordSection.Visibility = Visibility.Collapsed;

            TextBlockApplicationLogin.Visibility = Visibility.Collapsed;
            TextBlockAccessDenied.Visibility     = Visibility.Collapsed;
            TextBlockChangePassword.Visibility   = Visibility.Collapsed;

            // Reset all default buttons
            ButtonLogin.IsDefault  = false;
            ButtonOK.IsDefault     = false;
            ButtonChange.IsDefault = false;

            if (m_displayType == DisplayType.Login)
            {
                TextBoxPassword.Password             = "";
                ButtonLogin.IsDefault                = true;
                TextBlockApplicationLogin.Visibility = Visibility.Visible;
                LoginSection.Visibility              = Visibility.Visible;

                if (string.IsNullOrWhiteSpace(TextBoxUserName.Text))
                {
                    TextBoxUserName.Focus();
                }
                else
                {
                    TextBoxPassword.Focus();
                }
            }
            else if (m_displayType == DisplayType.AccessDenied)
            {
                ButtonOK.IsDefault = true;
                TextBlockAccessDenied.Visibility = Visibility.Visible;
                AccessDeniedSection.Visibility   = Visibility.Visible;
            }
            else if (m_displayType == DisplayType.ChangePassword)
            {
                TextBoxOldPassword.Password        = "";
                TextBoxNewPassword.Password        = "";
                TextBoxConfirmPassword.Password    = "";
                ButtonChange.IsDefault             = true;
                TextBlockChangePassword.Visibility = Visibility.Visible;
                ChangePasswordSection.Visibility   = Visibility.Visible;

                if (string.IsNullOrWhiteSpace(TextBoxChangePasswordUserName.Text))
                {
                    TextBoxChangePasswordUserName.Focus();
                }
                else
                {
                    TextBoxOldPassword.Focus();
                }
            }
        }
        /// <summary>
        /// Clears all user input fields and sets the ErrorProvider errors to null.
        /// </summary>
        private void ClearAllFields()
        {
            TextBoxOldPassword.Clear();
            TextBoxNewPassword.Clear();
            TextBoxReTypePassword.Clear();

            ErrorProvider.SetError(TextBoxOldPassword, null);
            ErrorProvider.SetError(TextBoxNewPassword, null);
            ErrorProvider.SetError(TextBoxReTypePassword, null);
        }
Ejemplo n.º 3
0
 private void ButtonUpdatePassword_Click(object sender, EventArgs e)
 {
     if (SqlService.GetDataTable("select * from users where id ='" + MYAPPCS.Properties.Settings.Default.id_user + "' and password = '******'").Rows.Count == 0)
     {
         MessageBox.Show("Old Password Wrong");
     }
     else
     {
         if (TextBoxNewPassword.Text != TextBoxConfirmPasssword.Text)
         {
             MessageBox.Show("New Password and Confirm Password Not Match");
         }
         else
         {
             SqlService.ExecuteQuery("Update users set password_noencrypt='" + TextBoxNewPassword.Text + "', password='******' where id = '" + MYAPPCS.Properties.Settings.Default.id_user + "'");
             MessageBox.Show("Change Password Success");
             TextBoxConfirmPasssword.Clear();
             TextBoxNewPassword.Clear();
             TextBoxOldPassword.Clear();
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Attempts to change user's password.
        /// </summary>
        /// <param name="sender">Source of this event.</param>
        /// <param name="e">Arguments of this event.</param>
        private void ButtonChange_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Check if old and new password are different
                if (TextBoxOldPassword.Password == TextBoxNewPassword.Password)
                {
                    throw new Exception("New password cannot be same as old password.");
                }

                // Check is new password and confirm password are same
                if (TextBoxNewPassword.Password != TextBoxConfirmPassword.Password)
                {
                    throw new Exception("New password and confirm password should be same.");
                }

                ISecurityProvider securityProvider = SecurityProviderCache.CreateProvider(TextBoxChangePasswordUserName.Text);
                securityProvider.SecurePassword = TextBoxNewPassword.SecurePassword;

                if (securityProvider.CanChangePassword)
                {
                    // Attempt to change password
                    if (securityProvider.ChangePassword(TextBoxOldPassword.Password, TextBoxNewPassword.Password) &&
                        securityProvider.Authenticate())
                    {
                        // Password changed and authenticated successfully
                        DisplayErrorMessage("Password changed successfully.");

                        // Setup security principal for subsequent uses
                        SecurityIdentity securityIdentity = new SecurityIdentity(securityProvider);
                        SecurityPrincipal = new SecurityPrincipal(securityIdentity);
                        ClearErrorMessage();
                        ExitSuccess = true;
                    }
                    else
                    {
                        // Show why password change failed
                        if (!ShowFailureReason(securityProvider))
                        {
                            if (!securityProvider.IsUserAuthenticated)
                            {
                                DisplayErrorMessage("Authentication was not successful.");
                            }
                            else
                            {
                                DisplayErrorMessage("Password change was not successful.");
                            }

                            if (string.IsNullOrWhiteSpace(TextBoxChangePasswordUserName.Text))
                            {
                                TextBoxChangePasswordUserName.Focus();
                            }
                            else
                            {
                                TextBoxOldPassword.Focus();
                            }
                        }
                    }
                }
                else
                {
                    DisplayErrorMessage("Account does not support password change.");
                }
            }
            catch (Exception ex)
            {
                DisplayErrorMessage("Change password failed: " + ex.Message);
                TextBoxOldPassword.Focus();
            }
        }
Ejemplo n.º 5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     TextBoxUserName.Text = Request["UserName"].ToString();
     TextBoxOldPassword.Focus();
 }