ASP.NET membership password expiration

前端 未结 6 543
感动是毒
感动是毒 2021-01-30 14:24

I am using ASP.NET membership for the authentication of my web app. This worked great for me. I now have to implement password expiration.

If the password has expired th

6条回答
  •  终归单人心
    2021-01-30 15:04

    I used the code from above and only slightly modified it to implement in Asp.NET (4.5) MVC5 using the .NET Identity Provider. Just leaving it here for the next guy/gal :)

    void Application_PostAuthenticateRequest(object sender, EventArgs e)
        {
            if (this.User.Identity.IsAuthenticated)
            {
                WisewomanDBContext db = new WisewomanDBContext();
    
                // get user
                var userId = User.Identity.GetUserId();
                ApplicationUser user = db.Users.Find(userId);
    
                // has their password expired?
                if (user != null && user.PasswordExpires <= DateTime.Now.Date
                    && !Request.Path.EndsWith("/Manage/ChangePassword"))
                {
                    Response.Redirect("~/Manage/ChangePassword");
                }
    
                db.Dispose();
            }
        }
    

提交回复
热议问题