How to get the windows login un and pw in c#
-
Can any one tell how to get the username and password from the windows login, for processing inside a c# windows application. Thanks in advance, regards,
VijayaRam
You cannot get the windows password.
Upcoming events: * Glasgow Geek Dinner (5th March) * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos
-
You cannot get the windows password.
Upcoming events: * Glasgow Geek Dinner (5th March) * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos
-
you can use System.Environment.UserName
-
Can any one tell how to get the username and password from the windows login, for processing inside a c# windows application. Thanks in advance, regards,
VijayaRam
It isnt possible to get the user password, however you can validate it using the follow api call
const int LOGON32_LOGON_INTERACTIVE = 2;
const int LOGON32_PROVIDER_DEFAULT = 0;[DllImport("advapi32.dll", SetLastError=true)]
private static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);private void DoLogonCheck(string userName, string domainName, string password)
{
IntPtr phToken = IntPtr.Zero;
bool logonRes = LogonUser(
userName,
domainName,
password,
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
ref phToken);if (logonRes)
{
Console.WriteLine("Good logon with username : {0}", userName)
}
else
{
Console.WriteLine("Bad logon with username : {0}", userName)
}
}I use a similar piece of code to validate that the user true user is sat in front of the machine and not that they have left it unlocked.