Пример #1
0
 private void btnPlayTheGame_Click(object sender, EventArgs e)
 {
     Quizz quizz = new Quizz();
     quizz.Show();
 }
Пример #2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            using (SqlConnection con = new SqlConnection(constr))
            {
                using (SqlCommand userExist = new SqlCommand("SELECT COUNT(*) FROM [User] WHERE Username = @Username", con))
                using (SqlCommand checkWw = new SqlCommand("SELECT Password  FROM [User] WHERE Username = @Username", con))
                using (SqlCommand userName = new SqlCommand("SELECT Username  FROM [User WHERE Username = @Username", con))
                {
                    int count;
                    string wachtwoord;

                    userExist.Parameters.AddWithValue("@Username", this.txtGebruikersNaam.Text);
                    checkWw.Parameters.AddWithValue("@Username", this.txtGebruikersNaam.Text);
                    userName.Parameters.AddWithValue("@Username", this.txtGebruikersNaam.Text);

                    string hashInput = GetMD5Hash(txtWachtwoord.Text);

                    con.Open();
                    count = (Int32)userExist.ExecuteScalar();
                    wachtwoord = (string)checkWw.ExecuteScalar();
                    con.Close();

                    if (count > 0 && string.Equals(hashInput, wachtwoord))
                    {
                        con.Open();
                        using (var reader = userName.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                var temp = reader["Username"];
                                if (temp != DBNull.Value)
                                {
                                    Current_User = reader["Username"].ToString();
                                    Quizz quiz = new Quizz();
                                    quiz.Show();
                                    this.Close();
                                }
                            }
                        }
                        con.Close();
                    }

                    else
                    {
                        MessageBox.Show("Gebruikersnaam/Wachtwoord is incorrect");
                        this.txtWachtwoord.Text = "";
                        this.txtGebruikersNaam.Focus();
                    }
                }
            }
        }