Exemple #1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string con = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

            SqlConnection conn = new SqlConnection(con);

            SqlCommand cmd  = new SqlCommand();
            SqlCommand cmd2 = new SqlCommand();
            int        count;
            string     username = txtUsername.Text;
            string     salt     = "aa07iubewfp9a8bp9web";
            string     Password = txtPassword.Text;
            string     NewPass  = Password + salt;
            var        dataSet  = new DataSet();

            SHA1CryptoServiceProvider sHA1CryptoServiceProvider = new SHA1CryptoServiceProvider();
            var sha1 = sHA1CryptoServiceProvider;

            var EncPass = sha1.ComputeHash(Encoding.UTF8.GetBytes(NewPass));

            var query = "SELECT COUNT (username) FROM users WHERE username = @username AND Pass = @Pass;";

            cmd = new SqlCommand(query, conn);

            cmd2 = new SqlCommand(query, conn);

            SqlParameter param = new SqlParameter();

            param.ParameterName = "@username";
            param.Value         = username;

            SqlParameter param2 = new SqlParameter();

            param2.ParameterName = "@Pass";
            param2.Value         = EncPass;

            cmd.Parameters.Add(param);
            cmd.Parameters.Add(param2);

            conn.Open();

            var reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                count = Convert.ToInt32(reader[0]);



                if (count > 0)
                {
                    this.Hide();
                    var QuizBody = new QuizBody();
                    username         = QuizBody.username;
                    QuizBody.Closed += (s, args) => this.Close();
                    QuizBody.Show();
                }
            }
            conn.Close();
        }
Exemple #2
0
        private void butSubmit_Click(object sender, EventArgs e)
        {
            if (radAnsw1.Text == corr_answer[i] && radAnsw1.Checked)
            {
                correct_answers++;

                answers[i] = true;

                this.Hide();
                var QuizBody = new QuizBody();
                username         = QuizBody.username;
                QuizBody.Closed += (s, args) => this.Close();
                QuizBody.Show();
            }
            else if (radAnsw2.Text == corr_answer[i] && radAnsw2.Checked)
            {
                correct_answers++;

                answers[i] = true;

                this.Hide();
                var QuizBody = new QuizBody();
                username         = QuizBody.username;
                QuizBody.Closed += (s, args) => this.Close();
                QuizBody.Show();
            }
            else if (radAnsw3.Text == corr_answer[i] && radAnsw3.Checked)
            {
                correct_answers++;

                answers[i] = true;

                this.Hide();
                var QuizBody = new QuizBody();
                username         = QuizBody.username;
                QuizBody.Closed += (s, args) => this.Close();
                QuizBody.Show();
            }
            else if (radAnsw4.Text == corr_answer[i] && radAnsw4.Checked)
            {
                correct_answers++;

                answers[i] = true;

                this.Hide();
                var QuizBody = new QuizBody();
                username         = QuizBody.username;
                QuizBody.Closed += (s, args) => this.Close();
                QuizBody.Show();
            }
            else
            {
                if (i == 9)
                {
                    this.Hide();
                    var FinalScreen = new FinalScreen();
                    correct_answers          = FinalScreen.correct_answers;
                    FinalScreen.answer_array = answers;
                    FinalScreen.Closed      += (s, args) => this.Close();
                    FinalScreen.Show();
                }
                else
                {
                    this.Hide();
                    var QuizBody = new QuizBody();
                    username         = QuizBody.username;
                    QuizBody.Closed += (s, args) => this.Close();
                    QuizBody.Show();
                }
            }
        }