Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. public static bool Login(string userName, string pass)
  2. {
  3. using (SqlConnection conn = new SqlConnection(connectionString))
  4. {
  5. try
  6. {
  7. conn.Open();
  8. string comand = string.Format("Select * From ChatUser Where " +
  9. "userName = '{0}' and pass ='{1}'", userName, pass);
  10. SqlCommand cmd = new SqlCommand(comand, conn);
  11. var reader = cmd.ExecuteReader();
  12. if (!reader.HasRows)
  13. {
  14. conn.Close();
  15. return false;
  16. }
  17. while (reader.Read())
  18. {
  19. string id = reader["id"].ToString();
  20. FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
  21. 1, id, DateTime.Now, DateTime.Now.AddMinutes(30),
  22. false, null, FormsAuthentication.FormsCookiePath);
  23. string hashCookies = FormsAuthentication.Encrypt(ticket);
  24. HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashCookies);
  25. HttpContext.Current.Response.Cookies.Add(cookie);
  26.  
  27. }
  28. conn.Close();
  29. JoinMesage();
  30. return true;
  31. }
  32.  
  33.  
  34. catch (Exception ex)
  35. {
  36. //write in log file
  37. return false;
  38. }
  39. }
  40. }
  41.  
  42. public static void JoinMesage()
  43. {
  44. string userId;
  45. if (HttpContext.Current.User != null)
  46. {
  47. userId = HttpContext.Current.User.Identity.Name;
  48. using (SqlConnection conn = new SqlConnection(connectionString))
  49. {
  50. string comand = string.Format("Insert into Messages (userID,mesageDate,userStatus)"
  51. + " Value('{0}','{1}','{2}')", userId, DateTime.Now, true);
  52. }
  53. }
  54.  
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement