我正在使用ASP.NET Membership API。我想強制用戶在第一次登錄後更改密碼。但是,我無法在ASP.NET的Membership API中找到任何此類內置功能。
是否有可能?如果是的話,怎麼能輕鬆完成呢?ASP.NET會員API強制密碼更改
5
A
回答
4
沒有內置功能。
你需要自己實現它。這裏有一個例子:http://forums.asp.net/p/1273575/2414481.aspx
8
給你,完全測試的解決方案;)
protected void LoginButton_Click(object sender, EventArgs e)
{
/****note: UserName and Password are textbox fields****/
if (Membership.ValidateUser(UserName.Text, Password.Text))
{
MembershipUser user = Membership.GetUser(UserName.Text);
if (user == null)
{
FailureText.Text = "Invalid username. Please try again.";
return;
}
if (user.IsLockedOut)
user.UnlockUser();
/* this is the interesting part for you */
if (user.LastPasswordChangedDate == user.CreationDate) //if true, that means user never changed their password before
{
//TODO: add your change password logic here
}
}
}
如果您需要在如何修改密碼幫助,請讓我知道。
這篇文章對你有幫助嗎,請標記爲答案
+1
至於LastPasswordChangedDate財產的替代方案,也可以使用Comment屬性(這只是一個自由格式的字符串)來指示用戶需要重置他們的密碼,以防您的更改密碼邏輯並不總是圍繞密碼更改日期。 – 2013-07-31 02:24:04
0
下面是VB中的解決方案。它還包括用於讀取和設置asp:Login ID="LoginUser"
表單元素的FindControl。
Protected Sub LoginButton_Click(sender As Object, e As EventArgs)
'***note: UserName and Password are textbox fields***
Dim UserName As TextBox = DirectCast(LoginUser.FindControl("UserName"), TextBox)
Dim Password As TextBox = DirectCast(LoginUser.FindControl("Password"), TextBox)
Dim FailureText As Literal = DirectCast(LoginUser.FindControl("FailureText"), Literal)
If Membership.ValidateUser(UserName.Text, Password.Text) Then
Dim user As MembershipUser = Membership.GetUser(UserName.Text)
If user Is Nothing Then
FailureText.Text = "Invalid username. Please try again."
Return
End If
If user.IsLockedOut Then
user.UnlockUser()
End If
' this is the interesting part for you
If user.LastPasswordChangedDate = user.CreationDate Then
'TODO: add your change password logic here
End If
End If
End Sub
0
這就是我做到的。最好是在登錄後做到這一點。
protected void LoginUser_LoggedIn(object sender, EventArgs e)
{
if (Membership.ValidateUser(this.LoginUser.UserName, this.LoginUser.Password))
{
MembershipUser user = Membership.GetUser(this.LoginUser.UserName);
if (user == null)
{
this.LoginUser.FailureText = "Invalid username. Please try again.";
return;
}
if (user.IsLockedOut)
{
user.UnlockUser();
}
if (user.LastPasswordChangedDate == user.CreationDate) //if true, that means user never changed their password before
{
Response.Redirect("~/Account/ChangePassword.aspx");
}
}
}
相關問題
- 1. 會員更改密碼
- 2. ASP.NET會員密碼?
- 3. 會員可以更改密碼
- 4. ASP.NET會員密碼重置
- 5. ASP.NET會員密碼到期
- 6. ASP.Net會員密碼恢復
- 7. asp.net會員密碼安全
- 8. Asp.net會員密碼格式
- 9. 強制更改/重置mysql密碼?
- 10. ASP.NET會員資格 - 更改密碼詢問舊
- 11. asp.net會員在不知道舊密碼的情況下更改密碼
- 12. 更改Umbraco會員密碼不知道舊密碼
- 13. asp.net會員通過用戶和管理員自定義更改密碼
- 14. asp.net會員如何在創建新用戶/更改密碼時限制密碼屬性?
- 15. 在機器密鑰更改期間維護ASP.Net成員密碼
- 16. Ad Asp.Net更改密碼
- 17. Asp.Net會員密碼無符號重置
- 18. asp.net會員 - 自定義密碼恢復
- 19. ASP.NET會員用戶忘記密碼
- 20. ASP.NET的密碼強度控制
- 21. CentOS的強行更改密碼問題
- 22. 在密碼更改後,舊密碼仍然工作在asp.net成員身份
- 23. ASP.NET會員控制重置密碼回發錯誤
- 24. 使用REST API後端在Web應用程序中強制更改密碼
- 25. ASP.NET成員變更密碼控制 - 需要檢查以前的密碼
- 26. ASP.NET成員資格配置工具 - 更改密碼?
- 27. 如何在asp.net成員資格中手動更改密碼?
- 28. ASP.NET成員身份更改密碼不起作用
- 29. 如何更改sonarqube管理員密碼
- 30. VBScript來更改Windows管理員密碼
http://forums.asp.net/p/1273575/2414481.aspx – 2012-03-19 13:07:54