Hi NG,
is there a way to get the Windows Password of a user in an encrypted
form?
In my logon process I want to check the current (windows) user and
password. If they fits no logon screen will be displayed and the
program starts.
Has somebody an idea how to get it?
The username is avaliable from .NET as Environment.Username
The password is stored in the registry. Accounts have a (meaningless?)
ID number that you have to look up in
HKLM/Security/SAM/Domains/Account/Users/Names/Username
The encrypted password for that user is at:
HKLM/Security/SAM/Domains/Account/Users/IDNumber
Note that by default only SYSTEM can access HKLM/Security but obviously
an administrator can set it so that they have access. It would be a
*very* bad idea to give non-administrators access to that (with read
access they could do an offline attack on admin passwords - with write
access they could change admin passwords and just log in), so only
administrators will be able to use your program.
On Vista and later versions of Windows, you're likely to irritate people
with dialogs asking if they're sure they want to give admin rights to
your program.
Vista also seems to store the value in a slightly different way to XP
(two keys). Perhaps they're salting the hash with the username - it
would be about time!
You should also note that if somebody gets access to your program's
data, they can trivially attack passwords on the system and get access.
So you'd better set your program's data file security attributes to only
allow admins access.
********
* NOTE *
********
While that answers your question, it's not actually what you want to do.
You could either use the LogonUser API (not avaliable on many older
versions of Windows and requires your program to have privilages to act
as part of the OS before Windows XP), or (probably better in your case)
use SSPI. These will do the authentication for you.
Full details and sample code on using SSPI are avaliable from here:
http://support.microsoft.com/kb/180548/EN-US/
Alun Harford