Пример #1
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            ClassDB db = new ClassDB();

            String username = uname.Text;
            String password = pass.Text;

            DataTable table = new DataTable();

            MySqlDataAdapter adapter = new MySqlDataAdapter();

            MySqlCommand command = new MySqlCommand("SELECT * FROM admin WHERE username = @uname and password= @pass", db.getConnection());

            command.Parameters.Add("@uname", MySqlDbType.VarChar).Value = username;
            command.Parameters.Add("@pass", MySqlDbType.VarChar).Value  = password;

            adapter.SelectCommand = command;

            adapter.Fill(table);

            // check if the user exists or not
            if (table.Rows.Count > 0)
            {
                MessageBox.Show("Login Berhasil", "Selamat Datang", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Hide();
                DataPendaftaran datapendaftaran = new DataPendaftaran();
                datapendaftaran.Show();
            }

            else
            {
                // check if the username field is empty
                if (username.Trim().Equals(""))
                {
                    MessageBox.Show("Enter Your Username To Login", "Empty Username", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                // check if the password field is empty
                else if (password.Trim().Equals(""))
                {
                    MessageBox.Show("Enter Your password To Login", "Empty password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                // check if the username or the password don't exist
                else
                {
                    MessageBox.Show("Wrong username or password", "Wrong Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #2
0
        public Boolean checkUsername()
        {
            ClassDB          db       = new ClassDB();
            String           username = tbUsername.Text;
            DataTable        table    = new DataTable();
            MySqlDataAdapter adapter  = new MySqlDataAdapter();
            MySqlCommand     command  = new MySqlCommand("SELECT * FROM admin WHERE username = @usn", db.getConnection());

            command.Parameters.Add("@usn", MySqlDbType.VarChar).Value = username;

            adapter.SelectCommand = command;

            adapter.Fill(table);

            // check if this username already exists in the database
            if (table.Rows.Count > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }