MembershipUser.LastPasswordChangedDate プロパティ
アセンブリ: System.Web (system.web.dll 内)

メンバシップ ユーザーのパスワードが最後に更新されたときの日時。

SqlMembershipProvider は CreationDate、LastLoginDate、LastActivityDate、および LastPasswordChangedDate の各日時を、メンバシップ ユーザーが CreateUser メソッドによって作成されたときの日時に設定します。

次のコード例は、指定の日数後に、パスワードの有効期限が過ぎていることを示すログイン ページを示しています。LastPasswordChangedDate が、現在の日時からパスワードの有効期限として指定されている日数を引いた日時より前になる場合、ユーザーにパスワードの変更を指示するメッセージが表示されます。
<%@ Page Language="VB" %> <%@ Import Namespace="System.Web.Security" %> <script runat="server"> Dim passwordExpiresDays As Double = 90 Public Sub Login_OnClick(sender As Object, args As EventArgs) Dim u As MembershipUser = Membership.GetUser(UsernameTextbox.Text) If u Is Nothing Then Msg.Text = "Invalid user name. Please check your user name and try again." Return End If If Membership.ValidateUser(UsernameTextbox.Text, PasswordTextbox.Text) Then If u.LastPasswordChangedDate.AddDays(passwordExpiresDays) < DateTime.Now Then Msg.Text = "Your password has expired. Please change your password to a new value." UsernameLabel.Text = UsernameTextbox.Text ChangePasswordPanel.Visible = True LoginPanel.Visible = False Else FormsAuthentication.RedirectFromLoginPage(UsernameTextbox.Text, NotPublicCheckBox.Checked) End If Else Msg.Text = "Invalid password. Please check your password and try again." End If End Sub Public Sub ChangePassword_OnClick(sender As Object, args As EventArgs) ' Update the password. Dim u As MembershipUser = Membership.GetUser(UsernameLabel.Text) If u.ChangePassword(OldPasswordTextbox.Text, NewPasswordTextbox.Text) Then Msg.Text = "Password changed." ChangePasswordPanel.Visible = False LoginPanel.Visible = True Else Msg.Text = "Password change failed. Please re-enter your values 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" /><BR> <asp:Panel id="LoginPanel" runat="Server"> 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. </asp:Panel> <asp:Panel id="ChangePasswordPanel" runat="Server" Visible="False"> <table CellPadding="3" border="0"> <tr> <td>Username:</td> <td><B><asp:Label id="UsernameLabel" runat="server" /></B></td> <td></td> </tr> <tr> <td>Old Password:</td> <td><asp:Textbox id="OldPasswordTextbox" runat="server" TextMode="Password" /></td> <td><asp:RequiredFieldValidator id="OldPasswordRequiredValidator" runat="server" ControlToValidate="OldPasswordTextbox" ForeColor="red" Display="Static" ErrorMessage="Required" /></td> </tr> <tr> <td>Password:</td> <td><asp:Textbox id="NewPasswordTextbox" runat="server" TextMode="Password" /></td> <td><asp:RequiredFieldValidator id="PasswordRequiredValidator" runat="server" ControlToValidate="NewPasswordTextbox" ForeColor="red" Display="Static" ErrorMessage="Required" /></td> </tr> <tr> <td>Confirm Password:</td> <td><asp:Textbox id="PasswordConfirmTextbox" runat="server" TextMode="Password" /></td> <td><asp:RequiredFieldValidator id="PasswordConfirmRequiredValidator" runat="server" ControlToValidate="PasswordConfirmTextbox" ForeColor="red" Display="Static" ErrorMessage="Required" /> <asp:CompareValidator id="PasswordConfirmCompareValidator" runat="server" ControlToValidate="PasswordConfirmTextbox" ForeColor="red" Display="Static" ControlToCompare="PasswordTextBox" ErrorMessage="Confirm password must match password." /> </td> </tr> <tr> <td></td> <td><asp:Button id="ChangePasswordButton" Text="Change Password" OnClick="ChangePassword_OnClick" runat="server" /></td> </tr> </table> </asp:Panel> </form> <P> </body> </html>
<%@ Page Language="C#" %> <%@ Import Namespace="System.Web.Security" %> <script runat="server"> double passwordExpiresDays = 90; public void Login_OnClick(object sender, EventArgs args) { MembershipUser u = Membership.GetUser(UsernameTextbox.Text); if (u == null) { Msg.Text = "Invalid user name. Please check your user name and try again."; return; } if (Membership.ValidateUser(UsernameTextbox.Text, PasswordTextbox.Text)) { if (u.LastPasswordChangedDate.AddDays(passwordExpiresDays) < DateTime.Now) { Msg.Text = "Your password has expired. Please change your password to a new value."; UsernameLabel.Text = UsernameTextbox.Text; ChangePasswordPanel.Visible = true; LoginPanel.Visible = false; } else { FormsAuthentication.RedirectFromLoginPage(UsernameTextbox.Text, NotPublicCheckBox.Checked); } } else { Msg.Text = "Invalid password. Please check your password and try again."; } } public void ChangePassword_OnClick(object sender, EventArgs args) { // Update the password. MembershipUser u = Membership.GetUser(UsernameLabel.Text); if (u.ChangePassword(OldPasswordTextbox.Text, NewPasswordTextbox.Text)) { Msg.Text = "Password changed."; ChangePasswordPanel.Visible = false; LoginPanel.Visible = true; } else { Msg.Text = "Password change failed. Please re-enter your values 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" /><BR> <asp:Panel id="LoginPanel" runat="Server"> 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. </asp:Panel> <asp:Panel id="ChangePasswordPanel" runat="Server" Visible="False"> <table CellPadding="3" border="0"> <tr> <td>Username:</td> <td><B><asp:Label id="UsernameLabel" runat="server" /></B></td> <td></td> </tr> <tr> <td>Old Password:</td> <td><asp:Textbox id="OldPasswordTextbox" runat="server" TextMode="Password" /></td> <td><asp:RequiredFieldValidator id="OldPasswordRequiredValidator" runat="server" ControlToValidate="OldPasswordTextbox" ForeColor="red" Display="Static" ErrorMessage="Required" /></td> </tr> <tr> <td>Password:</td> <td><asp:Textbox id="NewPasswordTextbox" runat="server" TextMode="Password" /></td> <td><asp:RequiredFieldValidator id="PasswordRequiredValidator" runat="server" ControlToValidate="NewPasswordTextbox" ForeColor="red" Display="Static" ErrorMessage="Required" /></td> </tr> <tr> <td>Confirm Password:</td> <td><asp:Textbox id="PasswordConfirmTextbox" runat="server" TextMode="Password" /></td> <td><asp:RequiredFieldValidator id="PasswordConfirmRequiredValidator" runat="server" ControlToValidate="PasswordConfirmTextbox" ForeColor="red" Display="Static" ErrorMessage="Required" /> <asp:CompareValidator id="PasswordConfirmCompareValidator" runat="server" ControlToValidate="PasswordConfirmTextbox" ForeColor="red" Display="Static" ControlToCompare="PasswordTextBox" ErrorMessage="Confirm password must match password." /> </td> </tr> <tr> <td></td> <td><asp:Button id="ChangePasswordButton" Text="Change Password" OnClick="ChangePassword_OnClick" runat="server" /></td> </tr> </table> </asp:Panel> </form> <P> </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に収録されているすべての辞書からMembershipUser.LastPasswordChangedDate プロパティを検索する場合は、下記のリンクをクリックしてください。

- MembershipUser.LastPasswordChangedDate プロパティのページへのリンク