Exemple #1
0
        private void cek_login(object sender, EventArgs e)
        {
            try
            {
                string          connectionSQL = "server=localhost;database=bmkg;uid=root;password=;";
                MySqlConnection myConn        = new MySqlConnection(connectionSQL);

                MySqlCommand SelectCommand = new MySqlCommand("select * from bmkg.user_ms where username='******' and pass='******' ", 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 Correct");
                    this.Hide();
                    Form frm2 = new adminpage(username_txt.Text);
                    frm2.Show();
                }
                else if (count > 1)
                {
                    MessageBox.Show("Duplicate Username and User, access denied");
                }
                else
                {
                    MessageBox.Show("Username and Password is incorrect, try again");
                }
                myConn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            /*{
             *  if ((username_txt.Text.Equals("putri")) && (password_txt.Text.Equals("password")))
             *  {
             *      MessageBox.Show("You are now Logged in");
             *      this.Hide();
             *      Form frm2 = new BMKG();
             *      frm2.Show();
             *
             *  }
             *  else if ((username_txt.Text.Equals("putri")) && (password_txt.Text != "password"))
             *  {
             *      MessageBox.Show("You have entered the wrong password! Try again");
             *      password_txt.Clear();
             *      password_txt.Focus();
             *  }
             *  else if ((username_txt.Text != "putri") && (password_txt.Text.Equals("password")))
             *  {
             *      MessageBox.Show("You have entered the wrong username! Try again");
             *      username_txt.Clear();
             *      username_txt.Focus();
             *  }
             *  else
             *  {
             *      MessageBox.Show("You have entered the wrong username and password! Try again");
             *      username_txt.Clear();
             *      password_txt.Clear();
             *  }
             * }*/
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection connection = new SqlConnection("Data Source=.;Initial Catalog=CarInsuranceSystem;Integrated Security=True");

            connection.Open();
            if (usernamelog.Text == "" || (usernamelog.Text.Trim() == "Username" && usernamelog.ForeColor == Color.DarkGray))
            {
                usernamelog.Focus();
            }
            else if (passwordlog.Text == "" || (passwordlog.ForeColor == Color.DarkGray && passwordlog.Text.Trim() == "Password"))
            {
                passwordlog.Focus();
            }
            else
            {
                SqlCommand command = new SqlCommand("Login", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter("@UserName", usernamelog.Text));
                command.Parameters.Add(new SqlParameter("@Password", passwordlog.Text));
                if (admin.Checked)
                {
                    command.Parameters.Add(new SqlParameter("@Admin", '1'));
                }
                else
                {
                    command.Parameters.Add(new SqlParameter("@Admin", '0'));
                }

                var returnParam1 = new SqlParameter {
                    ParameterName = "@@exist",
                    Direction     = ParameterDirection.Output,
                    Size          = 5
                };
                command.Parameters.Add(returnParam1);
                command.ExecuteNonQuery();

                if (command.Parameters["@@exist"].Value.ToString() == "Exist")
                {
                    connection.Close();
                    if (!admin.Checked)
                    {
                        this.Hide();
                        userPage f = new userPage(usernamelog.Text);
                        f.ShowDialog();
                        this.Close();
                    }
                    else
                    {
                        this.Hide();
                        adminpage f = new adminpage(usernamelog.Text);
                        f.ShowDialog();
                        this.Close();
                    }
                }

                else
                {
                    MessageBox.Show("Invalid Username or password.");
                }
                connection.Close();
            }
        }