Advertisement
Guest User

Untitled

a guest
May 28th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.HtmlControls;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11.  
  12. using System.Data.SqlClient;
  13. using System.Xml;
  14. using CRSSRSReports.Helpers;
  15.  
  16. //namespace CRSSRSReports
  17. //{
  18. public partial class Login : System.Web.UI.Page
  19. {
  20. const string XML_CONFIG_FILE = "reports.xml";
  21.  
  22. protected void Page_Load(object sender, EventArgs e)
  23. {
  24. if (!Page.IsPostBack)
  25. {
  26. ClearSession();
  27.  
  28. TryAutoLogin();
  29. }
  30.  
  31. // Compilation Directive
  32. // This will by-pass the authentication when DEV flag is added to Conditional Compilation Symbols
  33. // If not, it will ask for login as usual
  34. #if DEV
  35. txtPassword.Text = "test";
  36. btnLogin_Click(null, null);
  37. #endif
  38. }
  39.  
  40. private void TryAutoLogin()
  41. {
  42. if (Request.Params["uname"] == null)
  43. {
  44. return;
  45. }
  46.  
  47. ClearSession();
  48. lblMessage.Text = "";
  49.  
  50. // Perform Login based on the entered UserName and Password
  51. string sql = "Select * from Users U INNER JOIN UserReports UR ON U.UserName = UR.UserName where UR.ReportCode='R12' AND U.UserName = '" + Request.Params["uname"].Replace("'", "") + "' and Password = '" + Request.Params["pwd"].Replace("'", "") + "'";
  52. DataSet ds = Lib.GetResults(sql, ConnectionHelper.GetSecurityDatabaseConnection());
  53.  
  54. if (ds != null)
  55. {
  56. if (ds.Tables.Count > 0)
  57. {
  58. if (ds.Tables[0].Rows.Count == 1)
  59. {
  60. Session["UserName"] = Request.Params["uname"].Trim();
  61. Response.Redirect("Default.aspx");
  62. }
  63. else
  64. {
  65. lblMessage.Text = "Invalid UserName/Password.";
  66. }
  67. }
  68. else
  69. {
  70. lblMessage.Text = "Invalid UserName/Password.";
  71. }
  72. }
  73. else
  74. {
  75. lblMessage.Text = "Invalid UserName/Password.";
  76. }
  77. }
  78.  
  79. private void ClearSession()
  80. {
  81. // Clear all Session data
  82. Session.Clear();
  83. }
  84.  
  85. protected void btnLogin_Click(object sender, EventArgs e)
  86. {
  87. ClearSession();
  88. lblMessage.Text = "";
  89.  
  90. // Perform Login based on the entered UserName and Password
  91. string sql = "Select * from Users U INNER JOIN UserReports UR ON U.UserName = UR.UserName where UR.ReportCode='R12' AND U.UserName = '" + txtUserName.Text.Replace("'", "") + "' and Password = '" + txtPassword.Text.Replace("'", "") + "'";
  92. DataSet ds = Lib.GetResults(sql, ConnectionHelper.GetSecurityDatabaseConnection());
  93.  
  94. if (ds != null)
  95. {
  96. if (ds.Tables.Count > 0)
  97. {
  98. if (ds.Tables[0].Rows.Count == 1)
  99. {
  100. Session["UserName"] = txtUserName.Text.Trim();
  101. Response.Redirect("DashBoard.aspx");
  102.  
  103. }
  104. else
  105. {
  106. lblMessage.Text = "Invalid UserName/Password.";
  107. }
  108. }
  109. else
  110. {
  111. lblMessage.Text = "Invalid UserName/Password.";
  112. }
  113. }
  114. else
  115. {
  116. lblMessage.Text = "Invalid UserName/Password.";
  117. }
  118.  
  119. }
  120. }
  121.  
  122. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement