Advertisement
Guest User

Untitled

a guest
Feb 4th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.SqlClient;
  10.  
  11. namespace login
  12. {
  13.   public partial class LoginForm : Form
  14.   {
  15.     public LoginForm()
  16.     {
  17.       IntializeComponent();
  18.     }
  19.  
  20.     private void LoginBtn_Click(object sender, EventArgs e)
  21.     {
  22.        //Replace with whatever your SQL ConnectionString and Database Credentials are
  23.        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");
  24.        conn.Open();
  25.        //Sql select statement to validate against the users table
  26.        SqlCommand cmd = new SqlCommand("select * from UsersTable where username = '"+txtUsername.Text+"' and password = '" +txtPassword.Text+"'", conn);
  27.       SqlDataReader dr;
  28.       dr = cmd.ExecuteDataReader();
  29.       int count = 0;
  30.       while(dr.Read())
  31.       {
  32.          count += 1;
  33.       }
  34.  
  35.      if (count == 1)
  36.      {
  37.        MessageBox.Show("Login Successful");
  38.        Form2 BotForm = new Form2();
  39.        BotForm.Show();
  40.      }
  41.      else if (count > 0)
  42.      {
  43.         MeesageBox.Show("There is more than 1 user with these credentials, contact Admin.")
  44.      }
  45.      else
  46.      {
  47.         MessageBox.Show("ERROR: Credentials don't exist");
  48.      }
  49.      
  50.      txtUsername.Clear();
  51.      txtPassword.Clear();
  52.      Conn.Close();
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement