Skip to content
⌘ NSIS Forum Archive

Verifying serial number in installer itself

5 posts

roboldham#

Verifying serial number in installer itself

Hi there

This is what I need to do:

Customer purchases HTML content and PDFs off website, is given a serial number that is generated from their e-mail.

They then download their installer (written in NSIS of course!) and they then enter their email address and given serial number.

It doesnt need to be super secure, but I want to perform a simple check that the two match up.

I have some BASIC that can do it, but can it be implemented in NSIS scripting? (see below) MANY THANKS!

Function Encrypt(Text As String, EncryptKey As Integer)
Dim Temp As String, RR As Integer
For RR = 1 To Len(Text)
Temp$ = Temp$ + Chr$(Asc(Mid(Text, RR, 1)) Xor EncryptKey)
Next RR
Encrypt = Temp
End Function

Password = Encrypt(Password, Len(Password) + 77)
Joost Verburg#
Not all these functions are available, but there are similar instructions you can use to create basic encryption.

For more advanced stuff, you can write a C/C++/Delphi plug-in.
Afrow UK#
You need to firstly create an InstallOptions page (${NSISDIR}\Contrib\InstallOptions\)
With that you can use ReadINIStr to get entered values from field boxes / password boxes etc like so:
ReadINIStr $0 "$PLUGINSDIR\IOfile.ini" "Field 2" "State"

You can then compare your password like so:

StrCmp $0 [yourpassword] correct incorrect
correct:
;stuff to do if password is not wrong
Goto passend
incorrect:
;suff to do if password is wrong
passend:

You can get the user to re-enter their password using a messagebox:
MessageBox MB_OK|MB_ICONEXCLAMATION "Password incorrect!!!$\nYou must re-enter your given password." IDOK pagetop
That will jump to the pagetop label, which you put above the InstallOptions call like so:

Page Custom "PasswordDialog" "" " - Enter Serial Code"
Funcion PasswordDialog
File /oname=$PLUGINSDIR\iofile.ini "${NSISDIR}\myapp\iofile1.ini"
pagetop:

InstallOptions::dialog "$PLUGINSDIR\iofile.ini"
Pop $R0
StrCmp $R0 back pagebottom ;if user presses back
StrCmp $R0 cancel pagebottom ;if user presses cancel

ReadINIstr $R0 "$PLUGINSDIR\iofile.ini" "Field 2" "State"
StrCmp $R0 xyz321 passok

MessageBox MB_OK|MB_ICONEXCLAMATION "Serial Code is incorrect!" IDOK paketop

passok:
FunctionEnd

-Stu
roboldham#
Ok thanks guys, that gave me some pointers!

I am suprised no-one had tried this out yet!

Will let you know how I get on.

Thanks again

R