Lid |
|
Hoi,
Ik heb onderstaande method.
///// <summary>
///// Check if the user is allowed to log in.
///// </summary>
///// <param name="userName">Windows Username. DataType: System.String</param>
///// <param name="Password">Windows Password. DataType: System.String</param>
///// <returns>TRUE if the credentials are authenticated, FALSE if an error occurred.</returns>
public static bool AuthenticateUser(string userName, string password)
{
try
{
const string adDomain = "nlamv01rdc001.ad.eu.rf-group.org";
const string baseDn = "DC=ad, DC=eu, DC=rf-group, DC=org";
const string groupDn = "CN=GRP-BEVIL01-ICT-STAFF-M,OU=GROUPS,OU=EMRBE,OU=PRODUCTION";
bool authenticated = false;
string filter = "(&(objectclass=organizationalPerson)(&(memberOf=" + groupDn + "," + baseDn + ")(&(sAMAccountName=" + userName + "))))";
DirectoryEntry rootEntry = new DirectoryEntry("LDAP://" + adDomain, userName, password);
DirectorySearcher searcher = new DirectorySearcher(rootEntry);
searcher.PropertiesToLoad.Add("cn");
searcher.ClientTimeout = new TimeSpan(0, 1, 0);
searcher.ServerTimeLimit = new TimeSpan(0, 0, 30);
searcher.Filter = filter;
SearchResultCollection results = searcher.FindAll();
if (results.Count > 0)
{
authenticated = true;
}
return authenticated;
}
catch (DirectoryServicesCOMException exDirServCom)
{
throw new GeneralHelperClassesException(exDirServCom.Message);
}
catch (Exception ex)
{
throw new GeneralHelperClassesException(ex.Message);
}
}
///// <summary> ///// Check if the user is allowed to log in. ///// </summary> ///// <param name="userName">Windows Username. DataType: System.String</param> ///// <param name="Password">Windows Password. DataType: System.String</param> ///// <returns>TRUE if the credentials are authenticated, FALSE if an error occurred.</returns> public static bool AuthenticateUser(string userName, string password) { try { const string adDomain = "nlamv01rdc001.ad.eu.rf-group.org"; const string baseDn = "DC=ad, DC=eu, DC=rf-group, DC=org"; const string groupDn = "CN=GRP-BEVIL01-ICT-STAFF-M,OU=GROUPS,OU=EMRBE,OU=PRODUCTION"; bool authenticated = false; string filter = "(&(objectclass=organizationalPerson)(&(memberOf=" + groupDn + "," + baseDn + ")(&(sAMAccountName=" + userName + "))))"; DirectoryEntry rootEntry = new DirectoryEntry ("LDAP://" + adDomain, userName, password ); DirectorySearcher searcher = new DirectorySearcher (rootEntry ); searcher.PropertiesToLoad.Add("cn"); searcher. ClientTimeout = new TimeSpan (0, 1, 0); searcher. ServerTimeLimit = new TimeSpan (0, 0, 30); searcher.Filter = filter; SearchResultCollection results = searcher.FindAll(); if (results.Count > 0) { authenticated = true; } return authenticated; } catch (DirectoryServicesCOMException exDirServCom) { throw new GeneralHelperClassesException (exDirServCom. Message); } catch (Exception ex) { throw new GeneralHelperClassesException (ex. Message); } }
Wanneer ik een juiste username en password ingeef in de login box, is er geen probleem.
Wanneer ik echter een foutieve username of password ingeef, krijg ik een melding van VS dat ik een exception niet goed afhandel.
Exacte omschrijving:
GeneralHelperClassesException was unhandled by user code
Logon failure: unknown user name or bad password.
Iemand een idee wat?
Thanks!
|