Mega Code Archive

 
Categories / ASP.Net / Login Security
 

FormsAuthentication Authenticate (C#)

<%@ Page Language="C#"%> <script runat="server">     protected void Button1_Click(object sender, EventArgs e)     {         if (FormsAuthentication.Authenticate(TextBox1.Text, TextBox2.Text)) {             FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, true);         }         else {             Response.Write("Invalid credentials");          }     } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server">     <title>Login Page</title> </head> <body>     <form id="form1" runat="server">     <div>         Username<br />         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />         <br />         Password<br />         <asp:TextBox ID="TextBox2" runat="server"           TextMode="Password"></asp:TextBox><br />         <br />         <asp:Button ID="Button1" OnClick="Button1_Click" runat="server"           Text="Submit" />     </div>     </form> </body> </html> File: web.config   <system.web>    <authentication mode="Forms">       <forms name="form1" loginUrl="Login.aspx" path="/">          <credentials passwordFormat="Clear">             <user name="userName" password="Bubbles" />          </credentials>       </forms>    </authentication>        <authorization>       <deny users="?" />    </authorization> </system.web>