Beispiel #1
0
        /*.........................
        btnLogIn_Click - check the insert details into the log form.
         * If everything is ok close thit form and open the mainMenu form
        .........................*/
        private void btnLogIn_Click(object sender, EventArgs e)
        {
            int errorNumber = 0; //error counter
            sUsername = txtLogName.Text;

            if (txtLogName.Text != "" && txtLogPass.Text != "")
            {
                MySqlDataAdapter dAdapter = new MySqlDataAdapter("SELECT * FROM users", connStr);
                DataTable dTable = new DataTable();
                dAdapter.Fill(dTable);
                string name = txtLogName.Text;
                string password = txtLogPass.Text;
                //encrypt the inserted password to check it with the one into the database - md5
                byte[] encodedPassword = new UTF8Encoding().GetBytes(password);
                byte[] hash = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(encodedPassword);
                string encodedPass = BitConverter.ToString(hash).Replace("-", string.Empty).ToLower();

                foreach (DataRow row in dTable.Rows)
                {
                    if (row["name"].ToString() == name && row["password"].ToString() == encodedPass)
                    {
                        iUserId = Convert.ToInt32(row["id"]);
                        iUserWeight = Convert.ToInt32(row["weight"]);
                        mainMenu newMainMenu = new mainMenu();
                        newMainMenu.Show();
                        this.Hide();

                    }
                    else {
                        lblTest.Text = "Wrong user or pass";
                    }

                }
                dAdapter.Dispose();
            }
            else {
                lblTest.Text = "Please fill all the fields";
            }
        }
Beispiel #2
0
 /*.........................
 btnBack_Click - close this form and open the mainMenu form
 .........................*/
 private void btnBack_Click(object sender, EventArgs e)
 {
     mainMenu newMainMenu = new mainMenu();
     newMainMenu.Show();
     this.Hide();
 }