Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Data.SqlClient;
  7.  
  8. namespace FormProject
  9. {
  10. public class Login
  11. {
  12. string sqlConnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\Users\171296U\Desktop\Sensor-GroupProject\Database\Database.mdf;Integrated Security=True;Connect Timeout=30";
  13. bool isLoggedIn = false;
  14.  
  15. public bool TryDoingLogin(string user, string password)
  16. {
  17. string sqlstatement = "Select Count(*) from [User] where Username=@user and Password=@pass";
  18.  
  19. using (SqlConnection connection = new SqlConnection(sqlConnectionString))
  20. {
  21. using (SqlCommand command = new SqlCommand(sqlstatement, connection))
  22. {
  23. command.Parameters.AddWithValue("@user", user);
  24. command.Parameters.AddWithValue("@pass", password);
  25. connection.Open();
  26. SqlDataReader dr = command.ExecuteReader();
  27. if (dr.HasRows)
  28. {
  29. bool isLoggedIn = true;
  30. return true;
  31. }
  32. else
  33. {
  34. bool isLoggedIn = false;
  35. return false;
  36. }
  37. }
  38. }
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement