protected void LoginButton_Login(object sender, EventArgs e) { string UsrName = txtUserName.Text; string Password = txtPassword.Text; Guid UserGuid = Guid.Empty; ECXSecurityAccess.AuthenticationStatus AuStatus = new ECXSecurityAccess.ECXSecurityAccess().IsAuthenticated( HttpUtility.HtmlEncode(UsrName), HttpUtility.HtmlEncode(Password), "", out UserGuid); //ECXSecurityAccess.ECXSecurityAccess.HasRights(System.Guid, string[], string); if (AuStatus == ECXSecurityAccess.AuthenticationStatus.AccessGranted) { Session["UserGuid"] = UserGuid; Response.Redirect("~/Custodian.aspx"); //user.UserName = UserLogin.UserName; //user.UniqueIdentifier = UserGuid; //this.Session["LoggedUser"] = user; //FormsAuthentication.RedirectFromLoginPage(HttpUtility.HtmlEncode(UserLogin.UserName), false); //if (FormsAuthentication.GetRedirectUrl(HttpUtility.HtmlEncode(UserLogin.UserName), false) == "/default.aspx" || // FormsAuthentication.GetRedirectUrl(user.UserName, false) == "/Login.aspx") //{ // this.Response.Redirect("~/pHome.aspx"); //} //else //{ // this.Response.Redirect("~/pHome.aspx"); //} } else { loginfailLbl.Text = "Either your password or username is not correct. Please try again . . . "; } }
/*protected void UserLogin_Authenticate(object sender, AuthenticateEventArgs e) * { * string UserName = UserLogin.UserName; * string Password = UserLogin.Password; * * Guid UserGuid = Guid.Empty; * ECXSecurityAccess.AuthenticationStatus AuStatus = new ECXSecurityAccess.ECXSecurityAccess().IsAuthenticated( * HttpUtility.HtmlEncode(UserLogin.UserName), HttpUtility.HtmlEncode(UserLogin.Password), "", out UserGuid); * * if (AuStatus == ECXSecurityAccess.AuthenticationStatus.AccessGranted) * { * user.UserName = UserLogin.UserName; * user.UniqueIdentifier = UserGuid; * this.Session["LoggedUser"] = user; * FormsAuthentication.RedirectFromLoginPage(HttpUtility.HtmlEncode(UserLogin.UserName), false); * * if (FormsAuthentication.GetRedirectUrl(HttpUtility.HtmlEncode(UserLogin.UserName), false) == "/default.aspx" || * FormsAuthentication.GetRedirectUrl(user.UserName, false) == "/Login.aspx") * { * this.Response.Redirect("~/pHome.aspx"); * } * else * { * this.Response.Redirect("~/pHome.aspx"); * } * } * * * * * * * }*/ protected void UserLogin_Authenticate(object sender, AuthenticateEventArgs e) { string UserName = UserLogin.UserName; string Password = UserLogin.Password; Guid UserGuid = Guid.Empty; ECXSecurityAccess.AuthenticationStatus AuStatus = new ECXSecurityAccess.ECXSecurityAccess().IsAuthenticated( HttpUtility.HtmlEncode(UserLogin.UserName), UserLogin.Password, "", out UserGuid); if (AuStatus == ECXSecurityAccess.AuthenticationStatus.AccessGranted) { user.UserName = UserLogin.UserName; user.UniqueIdentifier = UserGuid; this.Session["LoggedUser"] = user; FormsAuthentication.RedirectFromLoginPage(HttpUtility.HtmlEncode(UserLogin.UserName), false); if (FormsAuthentication.GetRedirectUrl(HttpUtility.HtmlEncode(UserLogin.UserName), false) == "/default.aspx" || FormsAuthentication.GetRedirectUrl(user.UserName, false) == "/Login.aspx") { this.Response.Redirect("~/pHome.aspx"); } else { this.Response.Redirect("~/pHome.aspx"); } } /* SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); * SqlCommand command = new SqlCommand(); * SqlDataAdapter adapter = new SqlDataAdapter(command); * command.Connection = connection; * command.CommandType = CommandType.Text; * command.CommandText = "SELECT * FROM UserAccount WHERE UserName ='******' AND Password ='******'"; * DataTable tbl = new DataTable(); * try * { * connection.Open(); * command.ExecuteNonQuery(); * adapter.Fill(tbl); * } * finally * { * connection.Close(); * command.Dispose(); * } * if (tbl.Rows.Count == 1) * { * DataRow r = tbl.Rows[0]; * //DataTable tblEmployee = new CEmployee().GetRecord(new Guid(r["EmployeeGuid"].ToString())); * //if (tblEmployee.Rows.Count > 0) * //{ * // DataRow rEmployee = tblEmployee.Rows[0]; * // user.Name = rEmployee["Name"] + " " + rEmployee["FatherName"].ToString(); * //} * user.UserName = r["UserName"].ToString(); * user.UniqueIdentifier = new Guid(r["EmployeeGuid"].ToString()); * this.Session["LoggedUser"] = user; * * FormsAuthentication.RedirectFromLoginPage(user.UserName, false); * if (FormsAuthentication.GetRedirectUrl(user.UserName, false) == "/default.aspx" || FormsAuthentication.GetRedirectUrl(user.UserName, false) == "/Login.aspx") * { * this.Response.Redirect("~/pHome.aspx", false); * } * } * else * { * Session["LoggedUser"] = ""; * }*/ }