验证Windows用户名和密码

 

function NetUserChangePassword(servername, username, oldPassword, newPassword: PChar): Integer;
        external '[email protected] stdcall delayload';
function MultiByteToWideChar(CodePage, Flags: Integer; aStr: String; aLen: Integer; uStr: String; uLen: Integer): Integer;
        external '[email protected] stdcall';
function ValidateWindowsUser(userName, passWord: string) : Boolean;
var
 serverName, server_name, user_name, pass_word : String;
 status : LongInt;
begin
 SetLength(server_name, 256);
 SetLength(user_name, 256);
 SetLength(pass_word, 256);
 serverName := '' + ExpandConstant('{computername}');
 MultiByteToWideChar(0, 0, serverName, -1, server_name, 256);
 MultiByteToWideChar(0, 0, userName, -1, user_name, 256);
 MultiByteToWideChar(0, 0, passWord, -1, pass_word, 256);
 status := NetUserChangePassword(server_name, user_name, pass_word, pass_word);
 if(status = 0) then
  Result := True
 else
  Result := False
end;

你可能感兴趣的:(职场,休闲,验证Windows用户名和密码)