For security reasons we want to check if the current PC user is the actual logged on user. To do this we want the user to re-enter their password and check his credentials with the domain. How could we accomplish this?
Sofar we tried this:
public static Boolean Authenticate(String password)
{
String user = WindowsIdentity.GetCurrent().Name;
using (PrincipalContext PrincipalContext = new PrincipalContext(ContextType.Domain, Environment.UserDomainName))
{
return PrincipalContext.ValidateCredentials(user, password);
}
}
But get a System.DirectoryServices.Protocols.LdapException
, leaving the Environment.UserDomainName
off also triggers this exception.
We also tried:
public static Boolean Authenticate(String password)
{
String user = WindowsIdentity.GetCurrent().Name;
using (PrincipalContext PrincipalContext = new PrincipalContext(ContextType.Machine))
{
return PrincipalContext.ValidateCredentials(user, password);
}
}
But this returns true on any password.