FormsAuthentication.Authenticate (C#) : FormsAuthentication « Login Security « ASP.Net






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>

 








Related examples in the same category

1.FormsAuthentication.RedirectFromLoginPage (VB)
2.Checking credentials in SQL Server (VB)
3.Checking credentials in SQL Server (C#)
4.assigning a name to the user accessing next pages
5.FormsAuthentication.SignOut()
6.Hash password
7.Save user account to an XML file