This documentation is archived and is not being maintained.
FormsAuthentication.Authenticate Method
.NET Framework 1.1
Attempts to validate the credentials against those contained in the configured credential store, given the supplied credentials.
[Visual Basic] Public Shared Function Authenticate( _ ByVal name As String, _ ByVal password As String _ ) As Boolean [C#] public static bool Authenticate( string name, string password ); [C++] public: static bool Authenticate( String* name, String* password ); [JScript] public static function Authenticate( name : String, password : String ) : Boolean;
Parameters
- name
- The user name
- password
- The user password.
Return Value
true if the credentials are valid, otherwise returns false.
Example
[Visual Basic] <%-- This example shows how to authenticate a user and create a new cookie when the client is redirected to the original resource. --%> <%@ Import Namespace="System.Web.Security" %> <html> <script runat="server"> Sub BtnSubmit_Click(ByVal Source as Object, ByVal E as EventArgs) ' Pull credentials from form fields and try to authenticate the user. If FormsAuthentication.Authenticate(txtName.Text, txtPassword.Text) Then ' Redirect the client back to the originally requested resource and ' create a new persistent cookie that identifies the user. FormsAuthentication.RedirectFromLoginPage(txtName.Text, true) End If End Sub </script> <body> <Form method="Post" action="address.aspx" runat=server> <table width="250" bgcolor="#FFFF99"> <tr> <td Align="Right"><b>Name:</b></td> <td><Asp:Textbox id="txtName" runat=server/></td> </tr> <tr> <h4><td Align="Right"><b>Company:</b></td></h4> <td><Asp:Textbox id="txtPassword" runat=server/></td> </tr> </table><br> <asp:button id="btnSubmit" Text="Submit" OnClick="BtnSubmit_Click" runat=server/> <h4><asp:Label id="lblMsg1" runat=server/><h4> </form> </body> </html> [C#] <%-- This example shows how to authenticate a user and create a new cookie when the client is redirected to the original resource. --%> <%@ Import Namespace="System.Web.Security" %> <html> <script runat="server" language="C#"> void btnSubmit_Click(Object Source, EventArgs e) { FormsAuthenticationTicket ticket; // Pull credentials from form fields and try to authenticate the user. if (FormsAuthentication.Authenticate(txtName.Text, txtPassword.Text)) { // Redirect the client back to the originally requested resource and // create a new persistent cookie that identifies the user. FormsAuthentication.RedirectFromLoginPage(txtName.Text, true); } } </script> <body> <Form method="Post" action="address.aspx" runat=server> <table width="250" bgcolor="#FFFF99"> <tr> <td Align="Right"><b>Name:</b></td> <td><Asp:Textbox id="txtName" runat=server/></td> </tr> <tr> <h4><td Align="Right"><b>Company:</b></td></h4> <td><Asp:Textbox id="txtPassword" runat=server/></td> </tr> </table><br> <asp:button id="btnSubmit" Text="Submit" OnClick="btnSubmit_Click" runat=server/> <h4><asp:Label id="lblMsg1" runat=server/><h4> </form> </body> </html>
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
FormsAuthentication Class | FormsAuthentication Members | System.Web.Security Namespace
Show: