private void BtnLogin_Click(object sender, EventArgs e) { if (users.Contains(textUsername.Text) && password.Contains(textPassword.Text) && Array.IndexOf(users.ToArray(), textUsername.Text) == Array.IndexOf(password.ToArray(), textPassword.Text)) { DisplayStore openFormStore = new DisplayStore(); openFormStore.Show(); Visible = false; } else { MessageBox.Show("Username or password is incorrect!"); } }
private void BtnLogin_Click(object sender, EventArgs e) { if (users.Contains(textUsername.Text) && password.Contains(textPassword.Text) && Array.IndexOf(users.ToArray(), textUsername.Text) == Array.IndexOf(password.ToArray(), textPassword.Text)) { this.Hide(); DisplayStore f2 = new DisplayStore(); f2.ShowDialog(); this.Close(); } else { MessageBox.Show("Username or password is incorrect!"); } }
private void UserCheck(string username, string password) { DbConnect connect = new DbConnect(); try { using (SQLiteConnection connection = new SQLiteConnection(connect.connectionString)) { connection.Open(); int userCount = 0; string sql = @"SELECT Username, Password, email FROM UserData WHERE Username= '******' and Password = '******' "; SQLiteCommand cmd = new SQLiteCommand(sql, connection); SQLiteDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { userCount++; } if (userCount == 1) { MessageBox.Show("Login succes!", "Welcome", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); DisplayStore f2 = new DisplayStore(); f2.ShowDialog(); this.Close(); } else if (userCount == 0) { MessageBox.Show("Incorrect username or password!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } connection.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }