Beispiel #1
0
        //------------------------------------------------------------------------------------------------------
        //----------------------------Encrypt Password----------------------------------------------------------

        /*public static string MD5Hash(string input)
         * {
         *  StringBuilder hash = new StringBuilder();
         *  MD5CryptoServiceProvider md5provider = new MD5CryptoServiceProvider();
         *  byte[] bytes = md5provider.ComputeHash(new UTF8Encoding().GetBytes(input));
         *
         *  for (int i = 0; i < bytes.Length; i++)
         *  {
         *      hash.Append(bytes[i].ToString("x2")+"b");
         *  }
         *  return hash.ToString();
         * }*/
        //------------------------------------------------------------------------------------------------------
        //----------------------------------LOGIN---------------------------------------------------------------------------
        private void button1_Click(object sender, EventArgs e)
        {
            ID_USER = getID(txtUser.Text, FrmMain.MD5Hash(txtPass.Text));
            Perm    = getPer(txtUser.Text, FrmMain.MD5Hash(txtPass.Text));
            if ((txtUser.Text == "Admin") && (txtPass.Text == "123456"))
            {
                FrmMain Fmain = new FrmMain();
                this.Hide();
                Fmain.ShowDialog();
            }
            else
            {
                FrmMain.con1.Open();
            }
            String         query = @"(SELECT * FROM USER1 WHERE MaNV='" + txtUser.Text + "' AND Pass='******')";
            SqlDataAdapter sda   = new SqlDataAdapter(query, FrmMain.con1);
            DataTable      dt    = new DataTable();

            sda.Fill(dt);
            if (dt.Rows.Count == 1)
            {
                FrmMain FMain = new FrmMain();
                this.Hide();
                FMain.Show();
            }
            else
            {
                MessageBox.Show("Check User and Pass. Please!!!!!");
            }
            FrmMain.con1.Close();
        }