Inno Setup-如何在线验证序列号 [英] Inno Setup - How to validate serial number online
问题描述
使用Inno Setup,将setup.exe
分配给客户,根据合同,他只能使用2016年和2017年.但是在2018年1月1日,他应该不能继续使用相同的序列号2017年. >
如何使innosetup的setup.exe限制为自和至日期?
[Setup]
#define SerialNumber "2017"
UserInfoPage=yes
[Code]
function CheckSerial(Serial: String): Boolean;
begin
Result := Serial = '{#SerialNumber}';
end;
- setup.exe被执行
- 插入了许可证密钥
- 提交后,我要检查URL
https://www.stackoverflow.com/query/license?id=2017
- 如果结果表明安装成功或否,则
从以下代码开始: Inno设置-HTTP请求-获取www/web内容,您将获得类似的内容:
[Setup]
UserInfoPage=yes
[Code]
{ Presence of the CheckSerial event function displays the serial number box. }
{ But here we accept any non-empty serial. }
{ We will validate it only in the NextButtonClick, }
{ as the online validation can take long. }
function CheckSerial(Serial: String): Boolean;
begin
Result := (Serial <> '');
end;
function NextButtonClick(CurPageID: Integer): Boolean;
var
WinHttpReq: Variant;
Url: string;
begin
Result := True;
if CurPageID = wpUserInfo then
begin
WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
Url := 'https://www.example.com/serial.php?serial=' +
WizardForm.UserInfoSerialEdit.Text;
WinHttpReq.Open('GET', Url, False);
WinHttpReq.Send('');
{ Depending on implementation of the server, use wither HTTP status code (.Status) or }
{ contents of returned "page" (.ResponseText) }
{ Here we use the HTTP status code: }
{ 200 = serial is valid, anything else = serial is invalid, }
{ and when invalid, we display .ResponseText }
Result := (WinHttpReq.Status = 200);
if not Result then
MsgBox(WinHttpReq.ResponseText, mbError, MB_OK);
end;
end;
一个简单的服务器端验证PHP脚本(serial.php
)类似于:
<?
if (empty($_REQUEST["serial"]) || ($_REQUEST["serial"] != "2017"))
{
header("HTTP/1.0 401 The serial number is not valid");
// error message to be displayed in installer
echo "The serial number is not valid";
}
考虑:
- 通过验证(例如使用代理服务器)并不难.
- 它也不会阻止用户从安装程序中提取文件并手动安装它们.
- 您可以仅在验证序列号之后才考虑在线下载实际文件.
- 或下载该应用程序正常运行所需的一些许可证文件.无论如何,如果要在许可证到期后强制应用程序停止运行,则仍然需要.
有关类似问题,另请参见
如何将序列号存储在共享点列表中,以便从Inno Setup拨打电话并验证是否是授权用户?
Using Inno Setup, setup.exe
was given to a client, according to contract he is allowed only to use 2016 and 2017. But on 01-01-2018 he should not be able to continue with same serial 2017.
How to make the setup.exe by innosetup limited to from and to date?
[Setup]
#define SerialNumber "2017"
UserInfoPage=yes
[Code]
function CheckSerial(Serial: String): Boolean;
begin
Result := Serial = '{#SerialNumber}';
end;
- setup.exe is executed
- license key is inserted
- after submit, i want to check URL
https://www.stackoverflow.com/query/license?id=2017
- if the result is ok or nok based on that the installation continue
Starting with a code from: Inno Setup - HTTP request - Get www/web content, you will get something like:
[Setup]
UserInfoPage=yes
[Code]
{ Presence of the CheckSerial event function displays the serial number box. }
{ But here we accept any non-empty serial. }
{ We will validate it only in the NextButtonClick, }
{ as the online validation can take long. }
function CheckSerial(Serial: String): Boolean;
begin
Result := (Serial <> '');
end;
function NextButtonClick(CurPageID: Integer): Boolean;
var
WinHttpReq: Variant;
Url: string;
begin
Result := True;
if CurPageID = wpUserInfo then
begin
WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
Url := 'https://www.example.com/serial.php?serial=' +
WizardForm.UserInfoSerialEdit.Text;
WinHttpReq.Open('GET', Url, False);
WinHttpReq.Send('');
{ Depending on implementation of the server, use wither HTTP status code (.Status) or }
{ contents of returned "page" (.ResponseText) }
{ Here we use the HTTP status code: }
{ 200 = serial is valid, anything else = serial is invalid, }
{ and when invalid, we display .ResponseText }
Result := (WinHttpReq.Status = 200);
if not Result then
MsgBox(WinHttpReq.ResponseText, mbError, MB_OK);
end;
end;
A simple server-side validation PHP script (serial.php
) would be like:
<?
if (empty($_REQUEST["serial"]) || ($_REQUEST["serial"] != "2017"))
{
header("HTTP/1.0 401 The serial number is not valid");
// error message to be displayed in installer
echo "The serial number is not valid";
}
For consideration:
- This validation is not difficult to bypass, i.e. using a proxy server.
- It also does not prevent the user from extracting the files from the installer and installing them manually.
- You may consider instead an on-line download of the actual files only after validating the serial number.
- Or downloading some license file that the application will require for functioning. You need that anyway, if you want to enforce the application to stop working once the license expires.
For a similar question, see also
How to store serial numbers in a Sharepoint List, for to call from Inno Setup and verify if is autorized user?
这篇关于Inno Setup-如何在线验证序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!