MVC & Windows Authentication
- by TJ
Changed the ValidateUser function
public bool ValidateUser(string userName, string password)
{
bool validation;
try
{
LdapConnection ldc = new LdapConnection(new LdapDirectoryIdentifier((string)null, false, false));
NetworkCredential nc = new NetworkCredential(userName, password, "domainname.com");
ldc.Credential = nc;
ldc.AuthType = AuthType.Negotiate;
ldc.Bind(nc); // user has authenticated at this point, as the credentials were used to login to the dc.
string myvar = ldc.SessionOptions.DomainName;
validation = true;
}
catch (LdapException)
{
validation = false;
}
return validation;
}