joe_pool_is
Contributor
I have some code that authenticates my users with Active Directory.
An employee first enters their badge number, and if this badge number corresponds to an employee that is part of a secure group (Managers, Supervisors, etc.), that employee is required to authenticate who they are by entering their username and password.
This seemed to work fine until someone realized they could enter a supervisor's or manager's badge number, then authenitcate with their own username and password.
I want to edit my authentication routine to allow me to get the name of the individual that was authenticated.
From an Internet search, it looks like I need to use IADsGroup:
I tried a straight copy/paste of the above line, but 'IADsGroup' is not defined.
Doing more research, I see that this is part of the IADs Interface, which inherits from IDispatch (MSDN: http://msdn.microsoft.com/en-us/library/aa705950(VS.85).aspx).
I've never used interfaces before, and I don't know how to do what I want.
Could someone please give me some guidance?
An employee first enters their badge number, and if this badge number corresponds to an employee that is part of a secure group (Managers, Supervisors, etc.), that employee is required to authenticate who they are by entering their username and password.
Code:
public bool Authenticate(string domain, string userName, string passWord) {
string path = string.Format("[URL]ldap://{0[/URL]}", domain);
string domUser = domain + @"\" + userName;
DirectoryEntry entry = new DirectoryEntry(path, domUser, passWord);
try {
object nativeObj = entry.NativeObject;
Console.WriteLine(string.Format("Username '{0}' Authenticated", userName));
return true;
} catch (COMException e) {
MessageBox.Show(string.Format("Username '{0}' Not Authenticated:\n{1}", userName, e.Message), "Authentication Failed");
} catch (Exception e) {
MessageBox.Show(string.Format("Username '{0}' Not Authenticated:\n{1}", userName, e.Message), "Authentication Failed");
}
return false;
}
I want to edit my authentication routine to allow me to get the name of the individual that was authenticated.
From an Internet search, it looks like I need to use IADsGroup:
Code:
IADsGroup igroup = (IADsGroup)entry.NativeObject;
Doing more research, I see that this is part of the IADs Interface, which inherits from IDispatch (MSDN: http://msdn.microsoft.com/en-us/library/aa705950(VS.85).aspx).
I've never used interfaces before, and I don't know how to do what I want.
Could someone please give me some guidance?