1

In our project we have to use AD for authentication but we must also provide a logout mechanism. At the moment we are using Windows Authentication but there doesn't seem to be a way to logout.

My idea is to use Identity and to authenticate users like the following:

using (PrincipalContext context = new PrincipalContext(ContextType.Machine))
{
     var principal = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, userModel.Username);

     if (principal != null)
     {
        if (context.ValidateCredentials(userModel.Username, userModel.Password))
        {
           claims = AssignClaims(principal);
        }
     }
}

Basically, the user will be provided a login screen. Then he will enter his windows credentials and the code above will validate whether the user should have access.

One thing I've been having problems with is that the ValidateCredentials every now and then decides to stop working and even though I enter the proper credentials and the FindByIdentity finds the user ValidateCredentails returns false. Any idea what it could be? Is there a better method to use?

Does that look like a legit way of implementing it or are there issues with it?

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
Svet Angelov
  • 799
  • 8
  • 19
  • I'm not sure what's causing your problem, but you might want to read this SO item: https://stackoverflow.com/questions/25427013/use-activedirectory-authorization-with-asp-net-identity – Frank Fajardo Jun 16 '17 at 04:04

0 Answers0