.net - C#: How to figure out, if a Windows Account is Password proteced -


I know, if any WindowsAccount password is protected.

For security reasons, you password, this is obvious, but to know, if there is a password set then there should be a way.

  public bool ISACpointwordprosted (string username) {string entry string = "winnt: //" + environment Mikinam + ", Computer"; DirectoryEntry dirEntry = New directoryInterity (entry string); DirectoryEntry user = dirEntry.Children.Find (user name, "user"); // The first attempt was to check the ADS_UF_PASSWD_NOTREQD flag // If this flag is set, then there is no password in the account, but if not, then both are possible. Int userFlags = (int) user.Properties ["UserFlags"]. Values; Return (userflag and (int) activated.ADS_USER_FLAG.ADS_UF_PASSWD_NOTREQD) == 0; // The second attempt was to check PasswordAge int pwAge = (int) user.Properties ["PasswordAge"]. Values; Return PYAZ & gt; 0; } If there is no better way, I will use LogonUser-function, then I will use the LogonUser-function, But this is not the way I was looking for. But it is better than nothing if I use it for local account (not through network due to logon type) and for a competent account, then it should work. 

I used this two link:

  Public Bull ISAccitt Password Protection (String Username) {string Entry string = "winNT: //" + Environment.MachineName + ", computer"; DirectoryEntry dirEntry = New directoryInterity (entry string); DirectoryEntry user = dirEntry.Children.Find (user name, "user"); //// Edit: This flag can also be set if the password is in the account / int userFlags = (int) user.Properties ["UserFlags"]. Value; // if ((userFlags & (Active) ActiveDs.ADS_USER_FLAG.ADS_UF_PASSWD_NOTREQD)! = 0) // return false; IntPtr Tokens; Bool result = logon user (user.Name, Environment.UserDomainName, "", LogonTypes.Interactive, LogonProviders.Default, out of tokens); If (results) {CloseHandle (token); return false; } And {int err = Marshal.GetLastWin32Error (); If (err == 1327) // ERROR_ACCOUNT_RESTRICTION return false; // if (err == 1331) // ERROR_ACCOUNT_DISABLED Returns Correct; }} [DllImport ("advapi32.dll", SetLastError = true)) static extern bool LogonUser (string principal, string authorization, string password, LogonType logonType, LogonProviders logonProvider, IntPtr token outside); [DllImport ("kernel32.dll", SetLastError = true)] Fixed external button close handle (intake handles); Enum LogonTypes: UIT {interactive = 2, network, batch, service, network clertext = 8, newcredit} enum logonprovers: UIT {default = 0, default for platform / (use it!) WinNT35, // send signal signal to the authorization WinNT40, // NTLM WinNT50 / / / 

Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -