using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; 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.Xml.Linq; using System.Data.SqlClient; public partial class Home : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { } } static int count = 0; protected void log1_Authenticate(object sender, AuthenticateEventArgs e) { if (log1.UserName == "Admin" && log1.Password == "Admin") { Response.Redirect("Adminhome.aspx"); } else if (YourValidationFunction(log1.UserName, log1.Password)) { Session["User"]=log1.UserName; e.Authenticated = true; Response.Redirect("userhome.aspx"); log1.TitleText = "Successfully Logged In"; } else { e.Authenticated = false; count++; if (count >= 3) { count = 0; Session["User"] = log1.UserName; Server.Transfer("MainPage.aspx"); } } } SqlConnection strConnection = new SqlConnection("server=.\\SQLEXPRESS;database=honeypot;integrated security=true;"); private bool YourValidationFunction(string UserName, string Password) { bool boolReturnValue = false; String SQLQuery = "SELECT UserName, Password FROM Register"; SqlCommand command = new SqlCommand(SQLQuery, strConnection); SqlDataReader Dr; strConnection.Open(); Dr = command.ExecuteReader(); while (Dr.Read()) { if ((UserName == Dr["UserName"].ToString()) & (Password == Dr["Password"].ToString())) { boolReturnValue = true; } } Dr.Close(); return boolReturnValue; } protected void lnkRegis_Click(object sender, EventArgs e) { Response.Redirect("AdUserAcc.aspx"); } }
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="CodeInjection4.Home" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> </div> <asp:Login ID="log1" runat="server"> <layouttemplate> <table cellpadding="1" cellspacing="0" style="border-collapse:collapse;"> <tr> <td> <table cellpadding="0"> <tr> <td align="center" colspan="2">Log In</td> </tr> <tr> <td align="right"> <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name: </td> <td> <asp:TextBox ID="UserName" runat="server"> <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="log1">* </td> </tr> <tr> <td align="right"> <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password: </td> <td> <asp:TextBox ID="Password" runat="server" TextMode="Password"> <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="log1">* </td> </tr> <tr> <td colspan="2"> <asp:CheckBox ID="RememberMe" runat="server" Text="Remember me next time." /> </td> </tr> <tr> <td align="center" colspan="2" style="color:Red;"> <asp:Literal ID="FailureText" runat="server" EnableViewState="False"> </td> </tr> <tr> <td align="right" colspan="2"> <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="log1" /> </td> </tr> </table> </td> </tr> </table> </layouttemplate>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)