コード例 #1
0
        private void btn_Login_Click(object sender, EventArgs e)
        {
            String username        = txtUsername.Text;
            String password        = SecuirtyUtil.encodePassword(txtPassword.Text);
            String currentPassword = ConfigurationDAL.GetAdministratorPassword();

            if (username == ConfigurationDAL.ADMINISTRATOR)
            {
                if (password == currentPassword)
                {
                    gpAuthenticate.Hide();
                    lblAuthenticationStatus.Text = "Authentication Passed";
                    lblAuthenticationStatus.Show();
                    //frmSearchSales frmSearch = new frmSearchSales();
                    //frmSearch.ShowDialog();
                    authenticated = true;

                    this.Close();
                }
                else
                {
                    MessageBox.Show(this, "Incorrect Username or Password", "Login Form", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    //this.Close();
                }
            }
            else
            {
                MessageBox.Show(this, "Incorrect Username or Password", "Login Form", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                //this.Close();
            }
        }
コード例 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string existingPassword = ConfigurationDAL.GetAdministratorPassword();
                string currentPassword  = SecuirtyUtil.encodePassword(txtCurrentPassword.Text);

                string newPassword     = txtNewPassword.Text;
                string confirmPassword = txtConfirmPassword.Text;

                if (string.IsNullOrEmpty(txtCurrentPassword.Text))
                {
                    throw new Exception("Missing current password");
                }
                else if (currentPassword == existingPassword)
                {
                    if (newPassword == confirmPassword)
                    {
                        newPassword = SecuirtyUtil.encodePassword(newPassword);

                        ConfigurationDAL.UpdateConfigurationByName(ConfigurationDAL.ADMINISTRATOR, newPassword);
                        MessageBox.Show(this, "Password changed successfully", "Change Password", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                    }
                    else
                    {
                        throw new Exception("New Password and Confirm Password Mismatch");
                    }
                }
                else
                {
                    throw new Exception("Incorrect Password");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message.ToString(), "Error: Sale Item(s)", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }