Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            // getting the values from from
            String username = usernameRegister.Text;
            String password = passwordRegister.Text;
            String email    = emailRegister.Text;
            String confirm  = confirmPassword.Text;

            // adding a new user
            dataBase     db      = new dataBase();
            MySqlCommand command = new MySqlCommand("INSERT INTO `registration`(`Username`, `Email`, `Password`, `ActiveStatus`) VALUES (@user, @mail, @pass, @active)", db.getConnection());

            command.Parameters.Add("@user", MySqlDbType.VarChar).Value = username;
            command.Parameters.Add("@mail", MySqlDbType.VarChar).Value = email;
            command.Parameters.Add("@pass", MySqlDbType.Text).Value    = password;
            command.Parameters.Add("@active", MySqlDbType.Int32).Value = 1;

            if (!(username == "Username" || password == "Password" || email == "Email"))
            {
                if (password == confirm)
                {
                    if (!check())
                    {
                        // connection open
                        db.openConnection();

                        // execute command
                        if (command.ExecuteNonQuery() == 1)
                        {
                            this.Hide();
                            mainPage mp = new mainPage();
                            mp.ShowDialog();
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("Error");
                        }

                        // close connection
                        db.closeConnection();
                    }
                    else
                    {
                        MessageBox.Show("Username Already Taken!", "Duplicate user", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Passwords does not match!");
                }
            }
            else
            {
                MessageBox.Show("Enter Valid values!");
            }
        }
Ejemplo n.º 2
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            dataBase db = new dataBase();

            String username = Username.Text;
            String password = Password.Text;

            DataTable        table   = new DataTable();
            MySqlDataAdapter adapter = new MySqlDataAdapter();

            MySqlCommand command = new MySqlCommand("SELECT * FROM `registration` WHERE `Username` = @user and `Password` = @pass", db.getConnection());

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

            adapter.SelectCommand = command;
            adapter.Fill(table);

            // check if username exists or not
            if (table.Rows.Count > 0)
            {
                this.Hide();
                mainPage mp = new mainPage();
                mp.ShowDialog();
                this.Close();
            }
            else
            {
                if (username.Trim().Equals(""))
                {
                    MessageBox.Show("Enter Username to Continue!", "Empty Username");
                }
                else if (password.Trim().Equals(""))
                {
                    MessageBox.Show("Enter Password to Continue!", "Empty Password");
                }
                else
                {
                    MessageBox.Show("Wrong Username or Password!", "No User Found");
                }
            }
        }