Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Configuration;
- using System.Data;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Data.SqlClient;
- using System.Xml;
- using CRSSRSReports.Helpers;
- //namespace CRSSRSReports
- //{
- public partial class Login : System.Web.UI.Page
- {
- const string XML_CONFIG_FILE = "reports.xml";
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!Page.IsPostBack)
- {
- ClearSession();
- TryAutoLogin();
- }
- // Compilation Directive
- // This will by-pass the authentication when DEV flag is added to Conditional Compilation Symbols
- // If not, it will ask for login as usual
- #if DEV
- txtPassword.Text = "test";
- btnLogin_Click(null, null);
- #endif
- }
- private void TryAutoLogin()
- {
- if (Request.Params["uname"] == null)
- {
- return;
- }
- ClearSession();
- lblMessage.Text = "";
- // Perform Login based on the entered UserName and Password
- 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("'", "") + "'";
- DataSet ds = Lib.GetResults(sql, ConnectionHelper.GetSecurityDatabaseConnection());
- if (ds != null)
- {
- if (ds.Tables.Count > 0)
- {
- if (ds.Tables[0].Rows.Count == 1)
- {
- Session["UserName"] = Request.Params["uname"].Trim();
- Response.Redirect("Default.aspx");
- }
- else
- {
- lblMessage.Text = "Invalid UserName/Password.";
- }
- }
- else
- {
- lblMessage.Text = "Invalid UserName/Password.";
- }
- }
- else
- {
- lblMessage.Text = "Invalid UserName/Password.";
- }
- }
- private void ClearSession()
- {
- // Clear all Session data
- Session.Clear();
- }
- protected void btnLogin_Click(object sender, EventArgs e)
- {
- ClearSession();
- lblMessage.Text = "";
- // Perform Login based on the entered UserName and Password
- 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("'", "") + "'";
- DataSet ds = Lib.GetResults(sql, ConnectionHelper.GetSecurityDatabaseConnection());
- if (ds != null)
- {
- if (ds.Tables.Count > 0)
- {
- if (ds.Tables[0].Rows.Count == 1)
- {
- Session["UserName"] = txtUserName.Text.Trim();
- Response.Redirect("DashBoard.aspx");
- }
- else
- {
- lblMessage.Text = "Invalid UserName/Password.";
- }
- }
- else
- {
- lblMessage.Text = "Invalid UserName/Password.";
- }
- }
- else
- {
- lblMessage.Text = "Invalid UserName/Password.";
- }
- }
- }
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement