首次登录后强制用户更改密码使用窗体身份验证的asp.net mvc

问题描述:

我有一个mvc应用程序,它与表单身份验证安全客户端一起使用,所有管理用户的服务器端都使用wcf协议。
并在服务器站点,我用这个令牌我识别服务
和用户名形式认证节省了用户tocken在sessoin首次登录后强制用户更改密码使用窗体身份验证的asp.net mvc

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); 
    } 
} 
+0

第一我不隶属秒使用我的登录操作重定向,但我想,以防止来自changpassword页面使用不退出提交更改密码 – user2522878 2015-02-24 09:27:10

+0

如果您未使用成员身份,则必须使用某些内容来确定用户凭据是否有效。在用户表中,您可以维护一个标志isFirstTimeLoggedIn或将日期存储为LastPasswordChangedDate。这些是想法,您需要根据您的需求和当前设置找到解决方案。 – SBirthare 2015-02-24 10:34:07