Ejemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {

                string myConnection = "datasource=localhost;port=3306;username=root";
                MySqlConnection myConn = new MySqlConnection(myConnection);

                MySqlCommand SelectCommand = new MySqlCommand("select * from a1201409_dgn.users where username='******' and password ='******' ;", myConn);
                MySqlDataReader myReader;
                myConn.Open();
                myReader = SelectCommand.ExecuteReader();
                int count = 0;
                while (myReader.Read())
                {
                    count = count + 1;
                }

                if (count == 1)
                {
                    MessageBox.Show("Username and password is correct");
                    Form4 showf4 = new Form4();
                    showf4.Show();
                }

                else if (count > 1)
                {

                    MessageBox.Show("Duplicate Username and password..Access Denied");
                }

                else
                    MessageBox.Show("Username and password is not correct..Please try again");
                    myConn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Verify If the swipe was done successfully
            //If the string length = 39. Then The next form will allow user to input data
            //Else the swipe has to be repeated.

            if (L == 39)
            {

                //MessageBox.Show("Valid Swipe");

                //Get username
                int i = 1;
                int u_count = 0;
                int p_count = 0;
                while (i <= 4)
                {
                    User[u_count] = s[i];
                    i++;
                    u_count++;
                }

                //Get Password
                i = 12;
                while (i <= 17)
                {
                    password[p_count] = s[i];
                    i++;
                    p_count++;
                }

                //Convert arrays to string
                string UName = new string(User);
                string Pwd = new string(password);

                MessageBox.Show(UName + "   " + Pwd);

                                //Check database to validate user
                                string myConnection = "datasource=localhost;port=3306;username=root";
                                MySqlConnection myConn = new MySqlConnection(myConnection);

                                MySqlCommand SelectCommand = new MySqlCommand("select * from a1201409_dgn.validusers_card where UserName='******' and Password ='******' ;", myConn);
                                MySqlDataReader myReader;
                                myConn.Open();
                                myReader = SelectCommand.ExecuteReader();
                                int count = 0;
                                while (myReader.Read())
                                {
                                    count = count + 1;
                                }

                                if (count == 1)
                                {
                                    MessageBox.Show("Valid User");
                                    Form4 showf1 = new Form4();
                                    showf1.Show();

                                    //Clear input string so user has to re-swipe to get access
                                    textBox1.Clear();
                                    s = " ";

                                }

                                else

                                { MessageBox.Show("Access Denied"); }

                            }

             else
                {
                      MessageBox.Show("Please swipe card again");
                }
        }