Advertisement
Guest User

C# authentication by role in SQL DB table

a guest
Sep 7th, 2015
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. namespace WpfApplication1
  2. {
  3.     /// <summary>
  4.     /// Interaction logic for MainWindow.xaml
  5.     /// </summary>
  6.     public partial class MainWindow : Window
  7.     {
  8.        
  9.         public MainWindow()
  10.         {
  11.             InitializeComponent();
  12.         }
  13.  
  14.         private void button1_Click(object sender, RoutedEventArgs e)
  15.         {
  16.             SqlConnection con = new SqlConnection("Data Source=(local);Initial Catalog=Aukcija;Integrated Security=True");
  17.             con.Open();
  18.             SqlDataAdapter sda = new SqlDataAdapter("SELECT Role FROM users WHERE Username='"+ textBoxUser.Text +"' and Password='"+ passBoxPwd.Password + "' ", con);
  19.             DataTable dt = new DataTable();
  20.             sda.Fill(dt);
  21.             if (dt.Rows.Count == 1)
  22.             {
  23.                 this.Hide();
  24.                 Window1 w1 = new Window1();
  25.                 w1.Show();
  26.             }
  27.             con.Close();
  28.         }
  29.  
  30.         private void button2_Click(object sender, RoutedEventArgs e)
  31.         {
  32.             this.Close();
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement