Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- namespace login
- {
- public partial class LoginForm : Form
- {
- public LoginForm()
- {
- IntializeComponent();
- }
- private void LoginBtn_Click(object sender, EventArgs e)
- {
- //Replace with whatever your SQL ConnectionString and Database Credentials are
- SqlConnection conn = new SqlConnection("data source=(local);initial catalog=CIS;password=Tall^Money;persist security info=True;user id=CISdb;packet size=4096;Network Library=DBMSSOCN;Max Pool Size=1000");
- conn.Open();
- //Sql select statement to validate against the users table
- SqlCommand cmd = new SqlCommand("select * from UsersTable where username = '"+txtUsername.Text+"' and password = '" +txtPassword.Text+"'", conn);
- SqlDataReader dr;
- dr = cmd.ExecuteDataReader();
- int count = 0;
- while(dr.Read())
- {
- count += 1;
- }
- if (count == 1)
- {
- MessageBox.Show("Login Successful");
- Form2 BotForm = new Form2();
- BotForm.Show();
- }
- else if (count > 0)
- {
- MeesageBox.Show("There is more than 1 user with these credentials, contact Admin.")
- }
- else
- {
- MessageBox.Show("ERROR: Credentials don't exist");
- }
- txtUsername.Clear();
- txtPassword.Clear();
- Conn.Close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement