This code can be used in SharePoint custom Login form for user Validation for Claim based authentication or Form Based Authentication.
Reference Added :
COMException : The exception that is thrown when an unrecognized HRESULT is returned from a COM method call for more simplified error response from LDAP Error: Unknown error (0x80005000).
Below is the code sniplet
using (DirectoryEntry entry = new DirectoryEntry())
entry.Username = "DOMAIN\\LOGINNAME";
entry.Password = "PASSWORD";
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(objectclass=user)";
//Add Your Code if user Found..
catch (COMException ex)
if (ex.ErrorCode == -2147023570)
// Login or password is incorrect
ErrorCode : -2147023570 suggest the Username or password is not correctly entered.
post your questions, comments or suggestion.