I have an asp.net app which needs to log users into Active Directory using forms authentication (windows authentication isn\'t an option with the given requirements).
<Your code should read
if (Membership.ValidateUser(model.UserName, model.Password))
{
string userData = DateTime.Now.ToString();
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
username,
DateTime.Now,
DateTime.Now.AddMinutes(30),
isPersistent,
userData,
FormsAuthentication.FormsCookiePath);
// Encrypt the ticket.
string encTicket = FormsAuthentication.Encrypt(ticket);
// Create the cookie.
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
}
Now, when authenticating the user
HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.value);
if (DateTime.Parse(ticket.UserData) > Membership.GetUser().LastPasswordChangedDate)
{
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();
}