FormsAuthentication.Authenticate メソッド
アセンブリ: System.Web (system.web.dll 内)

Dim name As String Dim password As String Dim returnValue As Boolean returnValue = FormsAuthentication.Authenticate(name, password)
戻り値
ユーザー名とパスワードが有効な場合は true。それ以外の場合は false。

Authenticate メソッドは、アプリケーション構成ファイルの credentials セクションに格納されているユーザー資格情報に対して検証を行います。ASP.NET メンバシップを使用してユーザー資格情報を格納することもできます。詳細については、「メンバシップを使用したユーザーの管理」を参照してください。
セキュリティを高めるために、HashPasswordForStoringInConfigFile メソッドを使用して、アプリケーションの構成ファイルに格納されるパスワードを暗号化することもできます。

次のコード例に、アプリケーションの Web.config ファイルに格納されているユーザー資格情報を示します。パスワード値は、HashPasswordForStoringInConfigFile メソッドを使用してハッシュされています。
<authentication mode="Forms">
<forms loginUrl="login.aspx">
<credentials passwordFormat="SHA1">
<user name="user1" password="27CE4CA7FBF00685AF2F617E3F5BBCAFF7B7403C" />
<user name="user2" password="D108F80936F78DFDD333141EBC985B0233A30C7A" />
<user name="user3" password="7BDB09781A3F23885CD43177C0508B375CB1B7E9"/>
</credentials>
</forms>
</authentication>
次のコード例では、Authenticate メソッドを使用して、ユーザー資格情報を検証するログイン ページを示しています。
<%@ Page Language="VB" %> <%@ Import Namespace="System.Web.Security" %> <script runat="server"> Public Sub Login_OnClick(sender As Object, args As EventArgs) If FormsAuthentication.Authenticate(UsernameTextbox.Text, PasswordTextbox.Text) Then FormsAuthentication.RedirectFromLoginPage(UsernameTextbox.Text, NotPublicCheckBox.Checked) Else Msg.Text = "Login failed. Please check your user name and password and try again." End If End Sub </script> <html> <head> <title>Login</title> </head> <body> <form runat="server"> <h3>Login</h3> <asp:Label id="Msg" ForeColor="maroon" runat="server" /><P> Username: <asp:Textbox id="UsernameTextbox" runat="server" /><BR> Password: <asp:Textbox id="PasswordTextbox" runat="server" TextMode="Password" /><BR> <asp:Button id="LoginButton" Text="Login" OnClick="Login_OnClick" runat="server" /> <asp:CheckBox id="NotPublicCheckBox" runat="server" /> Check here if this is <u>not</u> a public computer. </form> </body> </html>
<%@ Page Language="C#" %> <%@ Import Namespace="System.Web.Security" %> <script runat="server"> public void Login_OnClick(object sender, EventArgs args) { if (FormsAuthentication.Authenticate(UsernameTextbox.Text, PasswordTextbox.Text)) FormsAuthentication.RedirectFromLoginPage(UsernameTextbox.Text, NotPublicCheckBox.Checked); else Msg.Text = "Login failed. Please check your user name and password and try again."; } </script> <html> <head> <title>Login</title> </head> <body> <form runat="server"> <h3>Login</h3> <asp:Label id="Msg" ForeColor="maroon" runat="server" /><P> Username: <asp:Textbox id="UsernameTextbox" runat="server" /><BR> Password: <asp:Textbox id="PasswordTextbox" runat="server" TextMode="Password" /><BR> <asp:Button id="LoginButton" Text="Login" OnClick="Login_OnClick" runat="server" /> <asp:CheckBox id="NotPublicCheckBox" runat="server" /> Check here if this is <u>not</u> a public computer. </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からFormsAuthentication.Authenticate メソッドを検索する場合は、下記のリンクをクリックしてください。

- FormsAuthentication.Authenticate メソッドのページへのリンク