How can I validate a username and password against Active Directory? I simply want to check if a username and password are correct.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Unfortunately there is no "simple" way to check a users credentials on AD.
With every method presented so far, you may get a false-negative: A user's creds will be valid, however AD will return false under certain circumstances:
ActiveDirectory will not allow you to use LDAP to determine if a password is invalid due to the fact that a user must change password or if their password has expired.
To determine password change or password expired, you may call Win32:LogonUser(), and check the windows error code for the following 2 constants:
My Simple Function
Try this code (NOTE: Reported to not work on windows server 2000)
except you'll need to create your own custom exception for "LogonException"
If you are stuck with .NET 2.0 and managed code, here is another way that works whith local and domain accounts:
very simple solution using DirectoryServices:
the NativeObject access is required to detect a bad user/password
Yet another .NET call to quickly authenticate LDAP credentials: