C# 强制用户在首次使用表单身份验证登录asp.net mvc后更改密码
我有一个mvc应用程序,用于表单身份验证安全客户端,所有管理用户的应用程序都是在服务器端使用wcf协议制作的。C# 强制用户在首次使用表单身份验证登录asp.net mvc后更改密码,c#,asp.net-mvc,web-config,C#,Asp.net Mvc,Web Config,我有一个mvc应用程序,用于表单身份验证安全客户端,所有管理用户的应用程序都是在服务器端使用wcf协议制作的。 在服务器站点中,我将用户保存在sessoin中 string token = Srv.ValidateUser(out isNewUser, model.UserName, model.Password, model.IdentityNumber); if (!string.IsNullOrEmpty(token)) { Session["Token"] = token; }
在服务器站点中,我将用户保存在sessoin中
string token = Srv.ValidateUser(out isNewUser, model.UserName, model.Password, model.IdentityNumber);
if (!string.IsNullOrEmpty(token))
{
Session["Token"] = token;
}
使用此令牌,我在服务中标识以及表单身份验证中的用户名
FormsAuthentication.SetAuthCookie(model.UserName, false);
现在我不知道如何强制用户在首次登录或密码过期后更改密码。我的配置是:
<system.web>
<sessionState mode="InProc" cookieless="true" timeout="20" />
<authentication mode="Forms">
<forms path="/" loginUrl="~/Account/Login" />
</authentication>
<authorization>
<allow users="*" />
<deny users="?" />
</authorization>
<identity impersonate="true" />
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthenticationModule" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
有人能帮我吗?在您的登录后操作中,您可以这样检查LastPasswordChangedDate:
var currentUser = Membership.GetUser(model.Email);
if (currentUser != null)
{
if (currentUser.LastPasswordChangedDate == currentUser.CreationDate)
{
// User has not changed password since created.
return RedirectPermanent("Login/?userName=" + model.Email);
}
}
首先,我不使用会员身份秒,我确实在登录操作中重定向,但我想防止在不提交更改密码的情况下使用退出密码页面。如果您不使用会员身份,您必须使用某种方法来确定用户凭据是否有效。在用户表中,可以维护标志isFirstTimeLoggedIn或将日期存储为LastPasswordChangedDate。这些是想法,您需要根据您的需要和当前设置找到解决方案。