Reputation: 6370
My setup installer downloads an ini file and fetches a value from it. I want to use this value as the password for the installer.
I can fetch the file and fetch the value, but I can't figure out how to set the password. I tried this, but pascal doesn't know the variable for 'password'
thispassword := getinistring('installer','key','George', expandconstant('{tmp}\' + inifilename) );
TPasswordEdit.password := thispassword;
Actually, I think TPasswordEdit
is just the edit box controls, anyway. But I've tried TPasswordEdit.text
too. (password
is a boolean anyway)
Can I even change the password via code?
Upvotes: 1
Views: 3866
Reputation: 6370
TLlama had the right answer when he suggested to use CheckPassword
. Up till then I thought that was the same as using the Password Wizard Page. But here is my final working code.
The idea here is to have an installer that only provides one chance for an automatic password.
This allows for different functionality:
Here is my working code in case anyone comes a-lookin':
[Code]
var
initialpassword: string;
procedure InitializeWizard;
begin
// initialize the downloader
ITD_Init;
itd_setoption('UI_AllowContinue', '1');
itd_addfile('http://www.somesite/somefile.txt', expandconstant('{tmp}\myini.ini') );
itd_downloadafter(wpWelcome);
end;
function CheckPassword(Password: String): Boolean;
var
returnvalue: boolean;
begin
initialpassword := getinistring('installer','key','', expandconstant('{tmp}\myini.ini'));
result := false;
if(password = initialpassword)then result := true;
if(password = 'MasterPassword')then result := true;
if(password = '')then result := false;
end;
Now, I haven't added the hashing yet for the password, but I am going to.
Upvotes: 1
Reputation: 76693
I won't directly answer your question, as it sounds that you actually need something else. I got your aim as that you want to download a file with the password and let the user enter such password to continue the installation. If that is so, I would do it this way (password is Hello
, case sensitive):
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
; note, that there is no Password defined here, because Password
; is fixed and must be defined at compilation time and cannot be
; used for case I described above
[Code]
const
Salt = ' world!';
function DownloadPasswordSomehow: string;
begin
// you will download an SHA-1 hash; this one is "Hello world!"
Result := 'd3486ae9136e7856bc42212385ea797094475802';
end;
function CheckPassword(Password: String): Boolean;
var
NetPwd: string;
begin
// download the password hash somehow, from somewhere
NetPwd := DownloadPasswordSomehow;
// and let the setup continue only when the SHA-1 hashed string
// of the entered password with some salt (password is "Hello",
// salt is " world!") matches to the downloaded hash
Result := GetSHA1OfString(Password + Salt) = NetPwd;
end;
Upvotes: 1