How to check if Windows user password is set?

Question

I did not know that it would be difficult to understand, but I am here.

I am developing a network support client that should determine if the current user in the system has a password. I tried it with WMI, checking the PasswordRequired property in the Win32_UserAccount class, but it returns false even if my account is password protected . I have no ideas ...

(Background: I need this information to tell the user that he needs to install it so that I can connect to it through the remote desktop, which is not very happy if the account is โ€œinsecure.โ€ If there is a way to get around this, I also accept another solution.)

Yours sincerely
Nefarius

Decision

Easier than I thought, I was able to use the WinAPI LogonUser function and provide you with this simple shell code:

  private bool PasswordRequired { get { IntPtr phToken; // http://www.pinvoke.net/default.aspx/advapi32/LogonUser.html bool loggedIn = LogonUser(Environment.UserName, null, "", (int)LogonType.LOGON32_LOGON_INTERACTIVE, (int)LogonProvider.LOGON32_PROVIDER_DEFAULT, out phToken); int error = Marshal.GetLastWin32Error(); if (phToken != IntPtr.Zero) // http://www.pinvoke.net/default.aspx/kernel32/CloseHandle.html CloseHandle(phToken); // 1327 = empty password if (loggedIn || error == 1327) return false; else return true; } } 

This is exactly what I need, thank you all for your prompt and competent answers, I can always count on you! =)

+7
source share
2 answers

Why not just try LogonUser with an empty password?

+7
source

From what I can find, windows do not save the text version of the user password. Windows stores a copy that has been protected by one-way encryption. You can find additional information about user registration in the windows in the MSDN documentation in the LSALogonUser function. This will not help you get a password for users.

+1
source

All Articles