WindowsAccountがパスワードで保護されているかどうかを知りたい。C#:Windowsアカウントがパスワードで保護されている場合の把握方法
セキュリティ上の理由から、パスワードは取得できませんが、明らかですが、パスワードが設定されているかどうかを確認する方法が必要です。
public bool IsAccountPasswordProteced(String userName)
{
String entryString = "WinNT://" + Environment.MachineName + ",Computer";
DirectoryEntry dirEntry = new DirectoryEntry(entryString);
DirectoryEntry user = dirEntry.Children.Find(userName, "User");
// First try was to check the ADS_UF_PASSWD_NOTREQD flag.
// If this flag is set, the account has no password,
// but if not, both is possible.
int userFlags = (int)user.Properties["UserFlags"].Value;
return (userFlags & (int)ActiveDs.ADS_USER_FLAG.ADS_UF_PASSWD_NOTREQD) == 0;
// Second try was to check the PasswordAge.
int pwAge = (int)user.Properties["PasswordAge"].Value;
return pwAge > 0;
}
彼らは私が「WindowsIdentityを持つ2つのアカウントの「identity.AuthenticationType」の値をテストしたP – DevinB