how i can use windows stored username and password in my C# APP. I am looking for method which returns bool state of successful login. means :
bool isCredentialValid = CheckLogin(username, password);
so according to bool value I can show proper message.
Updated
class Program
{
static void Main(string[] args)
{
PrincipalContext pc = new PrincipalContext(ContextType.Machine);
Console.WriteLine("Enter username : ");
string user = Console.ReadLine();
Console.WriteLine("Enter password : ");
string pass = Console.ReadLine();
bool isValid = pc.ValidateCredentials(user, pass);
Console.WriteLine("State : {0}",isValid);
Console.ReadLine();
}
}
this code is not working. when i enable Guest account it shows true for every login and when i disable Guest account it does not verifies even existing account. Any help would be appreciated.
Have a look at PrincipalContext.ValidateCredentials method. For example,
PrincipalContext pc = new PrincipalContext(ContextType.Domain);
bool isCredentialValid = pc.ValidateCredentials(username, password);
for local accounts, use ContextType.Machine.
Yet another way would be using win32 api LogonUser function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With