0
根據Microsoft文檔NetValidatePasswordPolicy有可能實現功能來檢查密碼歷史記錄並避免重複使用以前的密碼。我已經瀏覽了這個API的所有例子,但其中沒有一個爲我提供瞭如何檢查密碼歷史的功能。有人可以指導我如何驗證密碼歷史?使用NetValidatePasswordPolicy驗證以前散列密碼的密碼
public static NET_API_STATUS ValidatePassword(string password)
{
var outputArgs = new NET_VALIDATE_OUTPUT_ARG();
var inputArgs = new NET_VALIDATE_PASSWORD_CHANGE_INPUT_ARG();
var passwordHistory = new NET_VALIDATE_PASSWORD_HASH();
IntPtr inputPointer = IntPtr.Zero;
IntPtr outputPointer = IntPtr.Zero;
try
{
inputArgs.PasswordMatched = true;
inputArgs.ClearPassword = Marshal.StringToBSTR(password);
//var serverName = System.Environment.MachineName;
string userNameToCheck = @"usr";
//inputArgs.ClearPassword = Marshal.StringToBSTR(password);
inputArgs.UserAccountName = userNameToCheck;
// If using a secure string
////inputArgs.ClearPassword = Marshal.SecureStringToBSTR(secureStringPassword);
inputPointer = Marshal.AllocHGlobal(Marshal.SizeOf(inputArgs));
Marshal.StructureToPtr(inputArgs, inputPointer, false);
NET_API_STATUS status = NetValidatePasswordPolicy("serverdc1", IntPtr.Zero, NET_VALIDATE_PASSWORD_TYPE.NetValidatePasswordChange, inputPointer, ref outputPointer);
if (status == NET_API_STATUS.NERR_Success)
{
outputArgs = (NET_VALIDATE_OUTPUT_ARG)Marshal.PtrToStructure(outputPointer, typeof(NET_VALIDATE_OUTPUT_ARG));
NET_VALIDATE_PASSWORD_HASH OutPasswordHistory = new NET_VALIDATE_PASSWORD_HASH();
OutPasswordHistory.Hash = outputArgs.ChangedPersistedFields.PasswordHistory;
OutPasswordHistory.Length = outputArgs.ChangedPersistedFields.PasswordHistoryLength;
// Copy the Structure to the IntPtr
if (outputArgs.ValidationStatus == NET_API_STATUS.NERR_Success)
{
// Ok
string emtp;
}
return outputArgs.ValidationStatus;
}
else
{
return status;
}
}
如果整個政策得到驗證,對我來說沒問題,但我沒有收到有關密碼歷史記錄政策的錯誤。我附上了我使用的代碼。 – mikola 2014-09-03 06:51:15