protected void Button1_Click(object sender, EventArgs e) { //mp1.Hide(); try { SSAErrorLog logObj = new SSAErrorLog(); LdapAuthentication ldapObj = new LdapAuthentication(); string domainName = ConfigurationManager.AppSettings["domain"]; string displayVal = ldapObj.IsAuthenticatedStr(domainName, userNameTxt.Text, Session["pwd"].ToString()); DatabaseLayer dataObj = new DatabaseLayer(); logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "displayVal " + displayVal); if (displayVal != null) { Session["username"] = displayVal; string userid = userNameTxt.Text.ToLower(); Session["pwd"] = passwordTxt.Text; Session["userid"] = userid; // DatabaseLayer dataObj = new DatabaseLayer(); if (dataObj.getTablerowCount("userquestionanswers", "username='******'")) { Session["update"] = "yes"; } else { Session["update"] = "no"; } // Server.Transfer("SSAHome.aspx",true); //update session object.. string updateStr = "update usersession set sessionobj='" + Session[AntiXsrfTokenKey] + "' ,logincounter=0 where userid='" + userNameTxt.Text + "'"; dataObj.insertTableData(updateStr); Response.Redirect("SSAHome.aspx", false); } else { Errorlabel.Text = "Authentication Failed !!!"; Session.RemoveAll(); } } catch (Exception er) { Errorlabel.Text = "Authentication Failed !!!"; } }
protected void Login_Click(object sender, EventArgs e) { DatabaseLayer dataObj = new DatabaseLayer(); SSAErrorLog logObj = new SSAErrorLog(); try { if (ConfigurationManager.AppSettings["captchavalidation"].ToString().Equals("yes")) { if (txtimgcode.Text == Session["CaptchaImageText"].ToString()) { //lblmsg.Text = "Excellent......."; } else { lblmsg.Text = "Please Enter valid Captcha."; return; } this.txtimgcode.Text = ""; } logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "Loggedin"); LdapAuthentication ldapObj = new LdapAuthentication(); string domainName = ConfigurationManager.AppSettings["domain"]; string str = String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now); if (dataObj.getTablerowCount("usersession", "userid='" + userNameTxt.Text + "'")) { ArrayList userArray1 = new ArrayList(); userArray1.Add("userid"); userArray1.Add("sessionobj"); userArray1.Add("createddate"); userArray1.Add("logincounter"); ArrayList userArray = dataObj.getTableDataQuery("userid,sessionobj,createddate,logincounter from usersession", "userid='" + userNameTxt.Text + "'", "idusersession", userArray1); int counter = (int)Convert.ToInt64(userArray[3].ToString()); //DateTime createDate = (DateTime) userArray[2]; DateTime createDate = Convert.ToDateTime(userArray[2].ToString()); DateTime currentDate = DateTime.Now; int configCounter = (int)Convert.ToInt64(ConfigurationManager.AppSettings["nooftries"].ToString()); int sessionLock = (int)Convert.ToInt64(ConfigurationManager.AppSettings["sessionlock"].ToString()); string err = ConfigurationManager.AppSettings["sessionlockmsg"].ToString(); if (((currentDate - createDate).Minutes <= sessionLock) && (counter >= configCounter)) { int diffDate = (currentDate - createDate).Minutes; int remainingTime = sessionLock - diffDate; string errorMsg = string.Format(err, remainingTime); Errorlabel.Text = errorMsg; //"Please try after some time, User is locked due to no of tries are exceeded.."; //Response.Redirect("SSAHome.aspx"); // Session.RemoveAll(); return; } //Session[AntiXsrfTokenKey] //userid,sessionobj,createddate string updateStr = "update usersession set sessionobj='" + Session[AntiXsrfTokenKey] + "' ,logincounter=0 where userid='" + userNameTxt.Text + "'"; //dataObj.insertTableData("insert into usersession (userid,sessionobj,createddate,logincounter) values('" + userNameTxt.Text + "','" + Session[AntiXsrfTokenKey] + "','" + str + "',0)"); dataObj.insertTableData(updateStr); //dataObj.insertTableData("insert into usersession (userid,sessionobj,createddate,logincounter) values('" + userNameTxt.Text + "','" + Session[AntiXsrfTokenKey] + "','" + str + "',0)" ) ; string displayVal = ldapObj.IsAuthenticatedStr(domainName, userNameTxt.Text, passwordTxt.Text); logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "displayVal " + displayVal); //System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\login1.txt", "displayVal " + displayVal); //userNameTxt.Text = "done "; //Session["username"] = userNameTxt.Text; if (displayVal != null) { //System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\login2.txt", "displayVal " + displayVal); Session["username"] = displayVal; string userid = userNameTxt.Text.ToLower(); Session["pwd"] = passwordTxt.Text; Session["userid"] = userid; // DatabaseLayer dataObj = new DatabaseLayer(); if (dataObj.getTablerowCount("userquestionanswers", "username='******'")) { Session["update"] = "yes"; } else { Session["update"] = "no"; } Response.Redirect("SSAHome.aspx", false); } else { //userNameTxt.Text = "err"; Errorlabel.Text = "Authentication Failed !!!"; //Response.Redirect("SSAHome.aspx"); Session.RemoveAll(); } } else { Hashtable userHash = new Hashtable(); ArrayList userArray1 = new ArrayList(); userArray1.Add("userid"); userArray1.Add("sessionobj"); userArray1.Add("createddate"); userArray1.Add("logincounter"); //check the session here.. //userHash = dataObj.getTableData("usersession", userArray, "idusersession", "userid='" + userNameTxt.Text + "'"); // ArrayList dataValues = dataObj.getTableDataQuery("", "userid='" + userNameTxt.Text + "'", "idusersession", userArray); //get confirmation from request, If confirmed then login and update the session, //else terminate this request. // dialog.Visible = true; Session["pwd"] = passwordTxt.Text; // ArrayList userArray = dataObj.getTableDataQuery("userid,sessionobj,createddate,logincounter from usersession", "userid='" + userNameTxt.Text + "'", "idusersession", userArray1); // int counter = (int)Convert.ToInt64(userArray[3].ToString()); // DateTime createDate = Convert.ToDateTime(userArray[2].ToString()); // DateTime currentDate = DateTime.Now; int configCounter = (int)Convert.ToInt64(ConfigurationManager.AppSettings["nooftries"].ToString()); int sessionLock = (int)Convert.ToInt64(ConfigurationManager.AppSettings["sessionlock"].ToString()); string err = ConfigurationManager.AppSettings["sessionlockmsg"].ToString(); //LdapAuthentication ldapObj = new LdapAuthentication(); //string domainName = ConfigurationManager.AppSettings["domain"]; //string displayVal = ldapObj.IsAuthenticatedStr(domainName, userNameTxt.Text, Session["pwd"].ToString()); string displayVal = ldapObj.IsAuthenticatedStr(domainName, userNameTxt.Text, passwordTxt.Text); if (displayVal != null) { Session["username"] = displayVal; string userid = userNameTxt.Text.ToLower(); Session["pwd"] = passwordTxt.Text; Session["userid"] = userid; // DatabaseLayer dataObj = new DatabaseLayer(); if (dataObj.getTablerowCount("userquestionanswers", "username='******'")) { Session["update"] = "yes"; } else { Session["update"] = "no"; } // Server.Transfer("SSAHome.aspx",true); //update session object.. //string updateStr = "update usersession set sessionobj='" + Session[AntiXsrfTokenKey] + "' ,logincounter=0 where userid='" + userNameTxt.Text + "'"; dataObj.insertTableData("insert into usersession (userid,sessionobj,createddate,logincounter) values('" + userNameTxt.Text + "','" + Session[AntiXsrfTokenKey] + "','" + str + "',0)"); //dataObj.insertTableData(updateStr); Response.Redirect("SSAHome.aspx", false); } else { Errorlabel.Text = "Authentication Failed !!!"; Session.RemoveAll(); } /* * if (((currentDate- createDate).Minutes <= sessionLock) && (counter >= configCounter)) * { * int diffDate = (currentDate - createDate).Minutes; * int remainingTime = sessionLock - diffDate; * string errorMsg = string.Format(err, remainingTime); * Errorlabel.Text = errorMsg;//"Please try after some time, User is locked due to no of tries are exceeded.."; * //Response.Redirect("SSAHome.aspx"); * // Session.RemoveAll(); * return; * } * else * { * // mp1.Show(); * return; * } */ // userHash[] } /* * * string displayVal = ldapObj.IsAuthenticatedStr(domainName, userNameTxt.Text, passwordTxt.Text); * * * * logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "displayVal " + displayVal); * * //System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\login1.txt", "displayVal " + displayVal); * //userNameTxt.Text = "done "; * //Session["username"] = userNameTxt.Text; * if (displayVal != null) * { * //System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\login2.txt", "displayVal " + displayVal); * Session["username"] = displayVal; * * string userid = userNameTxt.Text.ToLower(); * Session["pwd"] = passwordTxt.Text; * Session["userid"] = userid; * * // DatabaseLayer dataObj = new DatabaseLayer(); * if (dataObj.getTablerowCount("userquestionanswers", "username='******'")) * { * Session["update"] = "yes"; * } * else * { * Session["update"] = "no"; * } * * // Server.Transfer("SSAHome.aspx",true); * Response.Redirect("SSAHome.aspx",false); * * } * else * { * //userNameTxt.Text = "err"; * Errorlabel.Text = "Authentication Failed !!!"; * //Response.Redirect("SSAHome.aspx"); * Session.RemoveAll(); * } */ } catch (Exception er) { //userNameTxt.Text = "err"; // System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\login3.txt", "displayVal " + er.Message + " StackTrace " + er.StackTrace); logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "Error While authenticating " + er.Message); Errorlabel.Text = "Authentication Failed !!!"; //Session.RemoveAll(); } }
protected void Login_Click(object sender, EventArgs e) { try { if (ConfigurationManager.AppSettings["captchavalidation"].ToString().Equals("yes")) { if (txtimgcode.Text == Session["CaptchaImageText"].ToString()) { //lblmsg.Text = "Excellent......."; } else { lblmsg.Text = "Please Enter valid Captcha."; return; } this.txtimgcode.Text = ""; } SSAErrorLog logObj = new SSAErrorLog(); logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "Loggedin"); LdapAuthentication ldapObj = new LdapAuthentication(); string domainName = ConfigurationManager.AppSettings["domain"]; string displayVal = ldapObj.IsAuthenticatedStr(domainName, userNameTxt.Text, passwordTxt.Text); logObj.ErrorLog(ConfigurationManager.AppSettings["logfilepath"].ToString(), "displayVal " + displayVal); //System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\login1.txt", "displayVal " + displayVal); //userNameTxt.Text = "done "; //Session["username"] = userNameTxt.Text; if (displayVal != null) { //System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\login2.txt", "displayVal " + displayVal); Session["username"] = displayVal; string userid = userNameTxt.Text.ToLower(); Session["pwd"] = passwordTxt.Text; Session["userid"] = userid; DatabaseLayer dataObj = new DatabaseLayer(); if (dataObj.getTablerowCount("userquestionanswers", "username='******'")) { Session["update"] = "yes"; } else { Session["update"] = "no"; } // Server.Transfer("SSAHome.aspx",true); Response.Redirect("SSAHome.aspx", false); } else { //userNameTxt.Text = "err"; Errorlabel.Text = "Authentication Failed !!!"; //Response.Redirect("SSAHome.aspx"); Session.RemoveAll(); } } catch (Exception er) { //userNameTxt.Text = "err"; // System.IO.File.WriteAllText(@"C:\SelfServiceAdminstration\login3.txt", "displayVal " + er.Message + " StackTrace " + er.StackTrace); Errorlabel.Text = "Authentication Failed !!!"; //Session.RemoveAll(); } }