Ejemplo n.º 1
0
        private void DoCheckOldPassword(object sender, EventArgs e)
        {
            /*if it is empty set automatically FAIL compare and return*/
            if (txtOldPassword.Text.Trim() == "")
            {
                txtNewPassword.Clear();
                txtRetypePassword.Clear();

                txtNewPassword.Enabled    = false;
                txtRetypePassword.Enabled = false;
                return;
            }

            if (ConvertHashCode.CompareDbHashWithInputHash(empLogin.Password, txtOldPassword.Text.Trim()))
            {
                txtNewPassword.Enabled    = true;
                txtRetypePassword.Enabled = true;
            }
            else
            {
                txtNewPassword.Clear();
                txtRetypePassword.Clear();

                txtNewPassword.Enabled    = false;
                txtRetypePassword.Enabled = false;
            }
        }
Ejemplo n.º 2
0
        private void DoLoginConfirmed(object sender, EventArgs e)
        {
            SqlCommand    cmd = null;
            SqlConnection con = Connection.getConnection();
            SqlDataReader dr;

            if (txtUsername.Text.Trim() == userHolder.Trim() || txtUsername.Text.Trim() == "")
            {
                MessageError("Please enter Username!", "Login");
                return;
            }
            else if (txtPassword.Text.Trim() == passHolder.Trim() || txtPassword.Text.Trim() == "")
            {
                MessageError("Please enter Password!", "Login");
                return;
            }

            try
            {
                con.Open();
                cmd             = new SqlCommand("CompareLogin", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@user", txtUsername.Text.Trim());
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    /* Compare Hash Code to Log In*/
                    if (ConvertHashCode.CompareDbHashWithInputHash((string)dr["password"], txtPassword.Text.Trim()))
                    {
                        Employee.CreatedInstance((int)dr["empID"], (string)dr["firstName"], (string)dr["lastName"], (string)dr["gender"], (DateTime)dr["birthDate"], (string)dr["username"], (string)dr["password"], new Role((int)dr["roleID"], (string)dr["roleName"]), (bool)dr["status"], (byte[])dr["photo"]);
                        break;
                    }
                }
            }
            catch (SqlException) { }
            finally
            {
                try
                {
                    cmd.Dispose();
                    con.Close();
                }
                catch (NullReferenceException ex)
                {
                }
            }

            if (Program.empLogin == null)
            {
                MessageError("Username or Password is incorrect", "Login");
            }
            else
            {
                if (checkBoxRemember.Checked)
                {
                    SavePassword(txtUsername.Text.Trim(), txtPassword.Text.Trim());
                }
                else
                {
                    SavePassword("", "");
                }

                FormMain frm = new FormMain();
                this.Hide();
                frm.ShowDialog();
            }
        }