Inno Setup根据外部信息设置密码

时间:2014-11-10 22:47:43

标签: inno-setup

我的设置安装程序会下载一个ini文件并从中获取一个值。我想将此值用作安装程序的密码。

我可以获取文件并获取值,但我无法弄清楚如何设置密码。我试过这个,但pascal不知道'密码'的变量

 thispassword := getinistring('installer','key','George', expandconstant('{tmp}\' + inifilename) );
 TPasswordEdit.password := thispassword;

实际上,无论如何,我认为TPasswordEdit只是编辑框控件。但我也试过TPasswordEdit.text。 (password无论如何都是一个布尔值)

我甚至可以通过代码更改密码吗?

2 个答案:

答案 0 :(得分:1)

我不会直接回答你的问题,因为听起来你确实需要别的东西。我的目标是你要下载一个带密码的文件,让用户输入这样的密码继续安装。如果是这样,我会这样做(密码为Hello,区分大小写):

[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;

答案 1 :(得分:1)

当他建议使用CheckPassword时,TLlama有正确的答案。到目前为止,我认为这与使用密码向导页面相同。但这是我最后的工作代码。

这里的想法是让安装程序只提供一次自动密码的机会。

这允许不同的功能:

  1. 首先,安装程序将下载文件并使用其中包含的密码。
  2. 如果文件无法使用,或密码错误,用户可以随时提供。
  3. 最后,IT团队可以使用主密码。
  4. 以下是我的工作代码,以防有人来看看':

    [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;
    

    现在,我还没有为密码添加哈希值,但我要去。

相关问题