This code can be used in SharePoint custom Login form for user Validation for Claim based authentication or Form Based Authentication.
Reference Added :
using System.Runtime.InteropServices;
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).
using System.DirectoryServices;
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)";
try
{
searcher.FindOne();
{
//Add Your Code if user Found..
}
}
catch (COMException ex)
{
if (ex.ErrorCode == -2147023570)
{
ex.Message.ToString();
// Login or password is incorrect
}
}
}
ErrorCode : -2147023570 suggest the Username or password is not correctly entered.
post your questions, comments or suggestion.