I am building a website that let's users log in with their Active Directory accounts, and I want to inform the user why their login failed.
The Background
Logins will usually fail due to a Bad Username/Password, but they can also fail due to an Expired Password or their account being Locked Out.
I am using this code to perform the login:
public myCustomUserClass Login(string domainName, string username, string password)
{
string domainAndUsername = domainName + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(this._ldapPath, domainAndUsername, password);
myCustomUserClass user = new myCustomUserClass();
//Bind to the native AdsObject to force authentication.
try
{
object obj = entry.NativeObject;
// ...
return user;
}
catch (DirectoryServicesCOMException ex)
{
// why did the login fail?
}
catch (Exception ex)
{
// something else went wrong
}
}
When I receive a DirectoryServicesCOMException
, I can access more information about the failed login attempt within the .ExtendedErrorMessage
property. Two values that I have seen so far are:
Lockout:
8009030C: LdapErr: DSID-0C0904DC, comment: AcceptSecurityContext error, data 775, v1db1
Bad Username:
8009030C: LdapErr: DSID-0C0904DC, comment: AcceptSecurityContext error, data 52e, v1db1
You can see that the data
"attribute" seems to be unique. I can write code that extracts it, then write a switch based off of this.
The Question
Is there a list of these codes anywhere that I can use to make sure that I'm covering everything?