예제 #1
0
 private void btnLogIn_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(this.txtUserName.Text))
     {
         UserNameErrorProvider.SetError(txtUserName, "Username empty!");
         txtUserName.Focus();
     }
     else if (string.IsNullOrWhiteSpace(this.txtPassword.Text))
     {
         PasswordErrorProvider.SetError(txtPassword, "Password empty!");
         txtPassword.Focus();
     }
     else
     {
         UserNameErrorProvider.Clear();
         PasswordErrorProvider.Clear();
         try {
             clsUtility.ExecuteSQLQuery(" SELECT * FROM Users WHERE  UserName = '******' AND Password = '******' ");
             if (clsUtility.sqlDT.Rows.Count > 0)
             {
                 clsUtility.UserID         = clsUtility.sqlDT.Rows[0]["USER_ID"].ToString();
                 clsUtility.UserName       = clsUtility.sqlDT.Rows[0]["UserName"].ToString();
                 clsUtility.UsersPrivilege = clsUtility.sqlDT.Rows[0]["Privilege"].ToString();
                 if (chkRememberMe.Checked)
                 {
                     Properties.Settings.Default.App_UserName     = txtUserName.Text;
                     Properties.Settings.Default.App_UserPassword = txtPassword.Text;
                 }
                 else
                 {
                     Properties.Settings.Default.App_UserName     = null;
                     Properties.Settings.Default.App_UserPassword = null;
                 }
                 Properties.Settings.Default.App_UserRemember = chkRememberMe.Checked;
                 Properties.Settings.Default.Save();
                 frmMDIParent frmMDIParent = new frmMDIParent();
                 frmMDIParent.Show();
                 this.Hide();
             }
             else
             {
                 lblWaring.Visible = true;
                 lblWaring.Text    = "No such user.";
             }
         }
         catch (Exception) {
             lblWaring.Visible = true;
             lblWaring.Text    = "Error executing sql statement.";
         }
     }
 }
예제 #2
0
        private void ChangePasswordButton_Click(object sender, EventArgs e)
        {
            User user = new User()
            {
                UserName = UserNameTextBox.Text.Trim(),
                Password = OriginalPasswordTextBox.Text.Trim()
            };
            Response response = new Response();

            if (string.IsNullOrEmpty(UserNameTextBox.Text.Trim()))
            {
                UserNameTextBox.Focus();
                UserNameErrorProvider.SetError(UserNameTextBox, "UserName can't be vacant!");
            }
            else
            {
                UserNameErrorProvider.SetError(UserNameTextBox, "");
                if (string.IsNullOrEmpty(OriginalPasswordTextBox.Text.Trim()))
                {
                    OriginalPasswordTextBox.Focus();
                    OriginalPasswordErrorProvider.SetError(OriginalPasswordTextBox, "OriginalPassword can't be vacant!");
                }
                else
                {
                    OriginalPasswordErrorProvider.SetError(OriginalPasswordTextBox, "");
                    if (string.IsNullOrEmpty(NewPasswordTextBox.Text.Trim()))
                    {
                        NewPasswordTextBox.Focus();
                        NewPasswordErrorProvider.SetError(NewPasswordTextBox, "NewPassword can't be vacant!");
                    }
                    else
                    {
                        NewPasswordErrorProvider.SetError(NewPasswordTextBox, "");
                        if (string.IsNullOrEmpty(ConfirmPasswordTextBox.Text.Trim()))
                        {
                            ConfirmPasswordTextBox.Focus();
                            ConfirmPasswordErrorProvider.SetError(ConfirmPasswordTextBox, "ConfirmPassword can't be vacant!");
                        }
                        else
                        {
                            try
                            {
                                response = new UserService().Authentication(user);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.ToString());
                            }
                            if (string.IsNullOrEmpty(response.Message))
                            {
                                if (NewPasswordTextBox.Text.Trim() != OriginalPasswordTextBox.Text.Trim())
                                {
                                    if (ConfirmPasswordTextBox.Text.Trim() == NewPasswordTextBox.Text.Trim())
                                    {
                                        try
                                        {
                                            user.UserId   = new UserService().GetUserIdByUserName(user.UserName);
                                            user.Password = ConfirmPasswordTextBox.Text.Trim();
                                            response      = new UserService().ChangePassword(user);
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show(ex.ToString());
                                        }
                                        if (response.IsFailed)
                                        {
                                            MessageBox.Show("Changing password fails", "System prompt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                            UserNameTextBox.Focus();
                                            UserNameTextBox.Text         = string.Empty;
                                            OriginalPasswordTextBox.Text = string.Empty;
                                            NewPasswordTextBox.Text      = string.Empty;
                                            ConfirmPasswordTextBox.Text  = string.Empty;
                                        }
                                        else
                                        {
                                            MessageBox.Show("Changing password succeeds", "System prompt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                            this.Close();
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Please repeat new password again.", "System prompt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                        NewPasswordTextBox.Text     = string.Empty;
                                        ConfirmPasswordTextBox.Text = string.Empty;
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("New password and current password are same.", "System prompt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    NewPasswordTextBox.Text     = string.Empty;
                                    ConfirmPasswordTextBox.Text = string.Empty;
                                }
                            }
                            else
                            {
                                MessageBox.Show(response.Message, "System prompt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                UserNameTextBox.Focus();
                                UserNameTextBox.Text         = string.Empty;
                                OriginalPasswordTextBox.Text = string.Empty;
                                NewPasswordTextBox.Text      = string.Empty;
                                ConfirmPasswordTextBox.Text  = string.Empty;
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
파일: UserLogin.cs 프로젝트: willdarwin/vms
        /// <summary>
        /// Excute user login  validation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LoginButton_Click(object sender, EventArgs e)
        {
            User user = new User()
            {
                UserName = UserNameTextBox.Text.Trim(),
                Password = PasswordTextBox.Text.Trim()
            };
            Response response = new Response();

            if (string.IsNullOrEmpty(UserNameTextBox.Text.Trim()))
            {
                UserNameTextBox.Focus();
                UserNameErrorProvider.SetError(UserNameTextBox, "UserName can't be vacant!");
            }
            else
            {
                UserNameErrorProvider.SetError(UserNameTextBox, "");
                if (string.IsNullOrEmpty(PasswordTextBox.Text.Trim()))
                {
                    PasswordTextBox.Focus();
                    PasswordErrorProvider.SetError(PasswordTextBox, "Password can't be vacant!");
                }
                else
                {
                    PasswordErrorProvider.SetError(PasswordTextBox, "");
                    if (string.IsNullOrEmpty(IdentifyingCodeTextBox.Text.Trim()))
                    {
                        IdentifyingCodeTextBox.Focus();
                        IdentifyingCodeErrorProvider.SetError(IdentifyingCodeTextBox, "IdentifyingCode can't be vacant!");
                    }
                    else
                    {
                        try
                        {
                            response = new UserService().Authentication(user);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                        if (string.IsNullOrEmpty(response.Message))
                        {
                            if (IdentifyingCodeTextBox.Text.Trim() == identifyingCode || IdentifyingCodeTextBox.Text.Trim().ToLowerInvariant() == identifyingCode.ToLowerInvariant() || IdentifyingCodeTextBox.Text.Trim().ToUpperInvariant() == identifyingCode.ToUpperInvariant())
                            {
                                Form f = Application.OpenForms["StaffList"];
                                if (f == null)
                                {
                                    f = new StaffList();
                                    f.Show();
                                    this.Hide();
                                }
                                else
                                {
                                    f.Show();
                                    this.Hide();
                                }
                            }
                            else
                            {
                                MessageBox.Show("Identifying code do not match!", "System prompt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                        else
                        {
                            MessageBox.Show(response.Message, "System prompt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ClearInformation();
                            Bind();
                        }
                    }
                }
            }
        }