Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than advapi32, prefix the name with the module name and a period.
// Don't use a managed string, you can't securely clean that up.
// Use Marshal.SecureStringToBSTR() and Marshal.ZeroFreeBSTR() to get and clean up a native string pointer.
public IntPtr ClearPassword;
[MarshalAs(UnmanagedType.LPWStr)]
public string UserAccountName;
public NET_VALIDATE_PASSWORD_HASH HashedPassword;
[MarshalAs(UnmanagedType.I1)]
public bool PasswordMatched;
}
[MarshalAs(UnmanagedType.LPWStr)]
public string ClearPassword;
[MarshalAs(UnmanagedType.LPWStr)]
public string UserAccountName;
public NET_VALIDATE_PASSWORD_HASH HashedPassword;
[MarshalAs(UnmanagedType.I1)]
public bool PasswordMustChangeAtNextLogon;
[MarshalAs(UnmanagedType.I1)]
public bool ClearLockout;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct NET_VALIDATE_PERSISTED_FIELDS
{
public uint PresentFields;
public ComTypes.FILETIME PasswordLastSet;
public ComTypes.FILETIME BadPasswordTime;
public ComTypes.FILETIME LockoutTime;
public uint BadPasswordCount;
public uint PasswordHistoryLength;
public IntPtr PasswordHistory;
}
try
{
inputArgs.ClearPassword = Marshal.StringToBSTR(@"password");
// If using a secure string
//inputArgs.ClearPassword = Marshal.SecureStringToBSTR(secureStringPassword);
NET_API_STATUS status = NetValidatePasswordPolicy(serverName, 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));
if (outputArgs.ValidationStatus == NET_API_STATUS.NERR_Success)
{
// Ok
}
else
{
Console.WriteLine(outputArgs.ValidationStatus);
}
}
else
{
Console.WriteLine(status);
}
}
finally
{
if (outputPointer != IntPtr.Zero)
{
NetValidatePasswordPolicyFree(ref outputPointer);
}
if (inputArgs.ClearPassword != IntPtr.Zero)
{
Marshal.ZeroFreeBSTR(inputArgs.ClearPassword);
}
if (inputPointer != IntPtr.Zero)
{
Marshal.FreeHGlobal(inputPointer);
}
}
}
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).