Advertisement
Guest User

Untitled

a guest
Sep 18th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. [WebMethod]
  2. public static string LoginValidation(string userName, string passWord)
  3. {
  4. string connectionString = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;
  5. SqlConnection con = new SqlConnection(connectionString);
  6. SqlCommand cmd = new SqlCommand("select * from LoginUser where username = '"
  7. + userName + "' and password = '" + passWord + "'");
  8. SqlDataReader rdr = cmd.ExecuteReader();
  9. if (rdr.HasRows)
  10. {
  11. return "succes";
  12. }
  13. return "failure";
  14. }
  15.  
  16. $(document).ready(function () {
  17. $('#txtLogin').focus();
  18. });
  19.  
  20. $('#btnLogin').click(function () {
  21. var username = $('#txtLogin').val();
  22. var password = $('#txtPassword').val();
  23.  
  24. if (username === "" || password === "") {
  25. alert('Both the fields are mandatory. Kindly try again');
  26. $('#txtLogin').focus();
  27. return;
  28. }
  29. else {
  30. //ajax call to validate the login
  31. $.ajax({
  32. type: 'POST',
  33. data: { 'userName': username, 'passWord': password },
  34. url: 'Default.aspx/LoginValidation',
  35. async: true,
  36. datatype: 'text',
  37. success: function (data) {
  38. alert('test sadfadfa '+data+' '+data.responseText);
  39. if (data == "failure") {
  40. //redirecting to master page once after the successfull login
  41. window.location.href = "/masterscreen.aspx";
  42. }
  43. else {
  44. alert('false');
  45. }
  46. return;
  47. },
  48. error: function (data) {
  49.  
  50. }
  51. });
  52. //ajax call end
  53. }
  54. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement