My requirement is to validate the password entered by a user is the correct password with which he had logged-in. So, I have written the below code, but it is always saying that "Not logged-in". Any help?
var
DomainName,UserName,BackwardSlashString,DomainUserName : String;
ServerDetailsInputPage : TInputQueryWizardPage;
hToken, LoginOk : INTEGER;
function LogonUser(lpszUsername,lpszDomain,lpszPassword: string;
dwLogonType,dwLogonProvider: INTEGER; var hToken: INTEGER): INTEGER;
external 'LogonUserA@advapi32.dll stdcall';
procedure InitializeWizard();
begin
DomainName:= ExpandConstant(GetEnv('USERDOMAIN'));
UserName := ExpandConstant( +GetUserNameString);
BackwardSlashString := '\'
DomainUserName := DomainName + BackwardSlashString + UserName;
ServerDetailsInputPage :=
CreateInputQueryPage(wpWelcome,'','','Please enter following data and click Next.');
ServerDetailsInputPage.Add('IP Address',False);
ServerDetailsInputPage.Add('Port Number',False);
ServerDetailsInputPage.Add('Domain Name\User Name',False);
ServerDetailsInputPage.Add('Password',True);
ServerDetailsInputPage.Values[1] := '80';
ServerDetailsInputPage.Values[2] := DomainUserName;
end;
function RunAsUser(): BOOLEAN;
var
Passwd : String;
begin
DomainName := ExpandConstant(GetEnv('USERDOMAIN'));
UserName := ExpandConstant( +GetUserNameString);
Passwd := ServerDetailsInputPage.Values[3];
LoginOk := LogonUser(UserName,DomainName,Passwd,1,0,hToken);
if (not (LoginOk=0)) then
begin
MsgBox('successfully logged-in', mbInformation, MB_OK);
Result := true;
end
else if (LoginOk=0) then
begin
MsgBox('Not logged-in', mbInformation, MB_OK);
Result := false;
end;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
Result := True;
if CurPageID = ServerDetailsInputPage.ID then
begin
if not RunAsUser then
begin
MsgBox('Please enter correct Password!', mbError, MB_OK);
Result:=False;
end;
end;
end;
function InitializeSetup(): Boolean;
var
PrevInstallPath : String;
ResultCode : Integer;
FXStopStatus : Boolean;
begin
Result:=True;
end;
At first, your
LogonUser
function prototype is wrong as well as its call. You can't mix data types of the function prototype and you can't use arbitrary values in a function call. You can use something like this instead: