Old 18th February 2013, 20:31   #1
Manchut
Junior Member
 
Join Date: Oct 2012
Posts: 21
Lightbulb Pass Daialog - problem with serial.txt

I use this code to create new install program with serial window. I read many topic on the forum and in the site wiki and don't know how (i'm not programmer) must create file with serials to compare values (install program and serial.txt). Please help me

PHP Code:
Name    "Serial"
OutFile "Serial.exe"

## Include headers
!include MUI.nsh
!include LogicLib.nsh

## Pages
 
!insertmacro MUI_PAGE_WELCOME
 Page custom SerialPageShow SerialPageLeave
;!define MUI_PAGE_CUSTOMFUNCTION_SHOW ComponentsPageShow
 
!insertmacro MUI_PAGE_COMPONENTS
 
!insertmacro MUI_PAGE_INSTFILES

## Languages
!insertmacro MUI_LANGUAGE English

## Displays the serial dialog
Function SerialPageShow

 
!insertmacro MUI_HEADER_TEXT "Enter Serial Code" "Enter the software serial code to continue."

PassDialog::Dialog Serial \
/
HEADINGTEXT 'Please enter the serial code located on the software CD case...' \
/
CENTER \
/
BOXDASH 12 70 4 '' \
/
BOXDASH 92 70 4 '' \
/
BOXDASH 172 70 4 '' \
/
BOXDASH 252 70 4 '' \
/
BOX 332 70 4 ''

Pop $R0 # success, back, cancel or error

FunctionEnd

## Validate serial numbers
Function SerialPageLeave

 
## Pop values from stack
 
Pop $R0
 Pop $R1
 Pop $R2
 Pop $R3
 Pop $R4

 Banner
::show "Please Wait....Your Serial Number is Validating..."

 
## A bit of validation

;StrCpy '$5' '$R0-$R1-$R2-$R3-$R4'
StrCpy '$5' '$R0-$R1-$R2-$R3-$R4$\r$\n'
StrCpy $6 0

Loop
:
IntOp $$1
StrCmp 
$6 500 Bad ;1 more than the # serials in file
Push $;line number to read from 
File 
/oname=$PLUGINSDIRserial.txt "c:\serial.txt"
Push "$PLUGINSDIR\serial.txt" ;text file to read 
Call ReadFileLine 
Pop 
$;output string (read from file.txt
StrCmp $$5 Good
Goto Loop

Bad
:
Banner::destroy
MessageBox MB_OK
|MB_ICONEXCLAMATION "The entered username or password is incorrect!"
Delete "$PLUGINSDIR\serial.txt"
Abort

Good
:
Delete "$PLUGINSDIR\serial.txt"
FunctionEnd

Function ReadFileLine
Exch 
$;file
Exch
Exch 
$;line number
Push 
$2
Push 
$3

  FileOpen 
$$0 r
 StrCpy 
$3 0
Loop
:
 
IntOp $$1
  ClearErrors
  FileRead 
$$0
  IfErrors 
+2
 StrCmp 
$$1 0 loop
  FileClose 
$2

Pop 
$3
Pop 
$2
Pop 
$1
Exch 
$0

FunctionEnd

## Just a dummy section
Section 'A section'
SectionEnd 
Manchut is offline   Reply With Quote
Old 19th February 2013, 21:50   #2
Manchut
Junior Member
 
Join Date: Oct 2012
Posts: 21
So maybe someone can tell me what plugin and how I must use to do this. Please help me guys
Manchut is offline   Reply With Quote
Old 20th February 2013, 09:01   #3
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
Could you give a clear description of what you need your serial page to do?
MSG is offline   Reply With Quote
Old 20th February 2013, 09:45   #4
Manchut
Junior Member
 
Join Date: Oct 2012
Posts: 21
When the serial page is display user must input serial code (he must buy a serial code before) to continue installation. I want integrate more than one serial in the installer but don't know how.
Manchut is offline   Reply With Quote
Old 20th February 2013, 16:35   #5
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
But what does the page need to *do*? How do you want it to look, how do you want it to behave? If all you need is a field to enter a serial code, simply create a custom page with nsDialogs that has two text fields. There's an excellent tutorial for that in the nsDialogs readme:
http://nsis.sourceforge.net/Docs/nsDialogs/Readme.html
MSG is offline   Reply With Quote
Old 20th February 2013, 22:00   #6
Manchut
Junior Member
 
Join Date: Oct 2012
Posts: 21
This page must compare code what user write with code enter in the file. I;m not programmer so i ask people who know something about this. I have script where i can put one serial to compare but i need more. I want ask if is possible and can somebody help me create this
Manchut is offline   Reply With Quote
Old 21st February 2013, 05:55   #7
T.Slappy
Major Dude
 
T.Slappy's Avatar
 
Join Date: Jan 2006
Location: Slovakia
Posts: 538
Send a message via ICQ to T.Slappy
So your idea is to have a list of valid keys and compare entered user's key against this list?
This may work but I think this is really risky - because you need to store your list of keys in installer (serials.txt), then unpack it to some directory (Temp) read the file (line by line) and do the comparison.

Every user can simply unpack your installer, grab key from the file and use it in the installer!!!

Maybe you could write your own plug-in (only C/C++ because C# plug-ins can decompiled easily) which would hold everything inside and it will do whole comparison for you.

Cool looking installers with custom design: www.graphical-installer.com
Design NSIS setup Pages easily: www.install-designer.com
Build NSIS installers in Visual Studio 2005-2019: www.visual-installer.com
or RAD Studio 2009, 2010, XE-10.3 Rio: www.rad-installer.com
T.Slappy is offline   Reply With Quote
Old 21st February 2013, 09:30   #8
Manchut
Junior Member
 
Join Date: Oct 2012
Posts: 21
Maybe is really risky but I don't programmer who know how create plugin. I never use language c/c++.
Manchut is offline   Reply With Quote
Old 21st February 2013, 10:52   #9
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
If it's really not important for you to be safe, simply do this:
- create custom page with nsDialogs (see nsDialogs tutorial I linked)
- add two text fields
- In the page's leave function, do
PHP Code:
${NSD_GetText$serial1_HWND $serial1
${NSD_GetText$serial2_HWND $serial2
${If} $serial1 == ${YourSerial1a}
${
OrIf$serial1 == ${YourSerial1b}
etc...
  
StrCpy $serial1valid yes
${Else}
  
StrCpy $serial1valid no
${EndIf}
${If} 
$serial2 == ${YourSerial2a}
${
OrIf$serial2 == ${YourSerial2b}
etc...
  
StrCpy $serial2valid 'yes'
${Else}
  
StrCpy $serial1valid 'no'
${EndIf}

${If} 
$serial1valid != yes
${OrIf$serial2valid != yes
  MessageBox MB_OK 
"Invalid serial(s)!"
  
abort
${EndIf} 
MSG is offline   Reply With Quote
Old 21st February 2013, 21:59   #10
Manchut
Junior Member
 
Join Date: Oct 2012
Posts: 21
It is still difficult ....
Manchut is offline   Reply With Quote
Old 22nd February 2013, 08:21   #11
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
Have you followed the tutorial in the nsDialogs readme?
MSG is offline   Reply With Quote
Old 22nd February 2013, 08:59   #12
Manchut
Junior Member
 
Join Date: Oct 2012
Posts: 21
Yes I read and try do something but for me is not easy

PHP Code:
## Pages
 
!insertmacro MUI_PAGE_WELCOME
 Page custom SerialPageShow SerialPageLeave
;!define MUI_PAGE_CUSTOMFUNCTION_SHOW ComponentsPageShow
 
!insertmacro MUI_PAGE_COMPONENTS
 
!insertmacro MUI_PAGE_INSTFILES

## Languages
!insertmacro MUI_LANGUAGE English

Var serial1
Var serial2
Var serial1valid
Var serial2valid
var serial1_HWND

## Displays the serial dialog
Function SerialPageShow

!insertmacro MUI_HEADER_TEXT "Enter Serial Code" "Enter the software serial code to continue."

 
     
PassDialog::Dialog Serial 
     
\
                    /
HEADINGTEXT 'Please enter the serial code' \
                    /
CENTER             \
                    /
BOX 152 70 5 '' 
                    
Pop $serial1_HWND 
        
    
!define YourSerial1a "12345"
    
!define YourSerial2a "12346"
    


nsDialogs::Show


FunctionEnd 

Last edited by Manchut; 22nd February 2013 at 10:55.
Manchut is offline   Reply With Quote
Old 22nd February 2013, 14:20   #13
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
You are mixing nsDialogs and PassDialog. They are different plugins, don't use them together on one installer page. If you want to use passdialog, follow the example in PassDialog.zip\Examples\PassDialog\Serial.nsi .
MSG is offline   Reply With Quote
Old 22nd February 2013, 14:34   #14
Manchut
Junior Member
 
Join Date: Oct 2012
Posts: 21
I try used PassDialog but don't work (i can only put one serial) In nsDialogs i create custom page but I don't what code i must use to work with your scirpt

PHP Code:
nsDialogs::Create 1018
        Pop $serial1_HWND
 
 
    
${NSD_CreatePassword0 10508""
        
Pop $serial1
    
    
    
!define YourSerial1a "12345"
    
!define YourSerial2a "12346"
    


nsDialogs::Show 
Manchut is offline   Reply With Quote
Old 23rd February 2013, 17:44   #15
Manchut
Junior Member
 
Join Date: Oct 2012
Posts: 21
no progress... please help ;/
Manchut is offline   Reply With Quote
Old 24th February 2013, 11:54   #16
Manchut
Junior Member
 
Join Date: Oct 2012
Posts: 21
Quote:
Originally Posted by Manchut View Post
no progress... please help ;/
PHP Code:
Function SerialPageShow

InitPluginsDir
nsDialogs
::Create 1018
 
    
${NSD_CreatePassword0 10508""
        
Pop $give_HWND
 
${NSD_LB_GetSelection$give_HWND $serial1_HWND

${NSD_SetText$serial1 ${12345}

nsDialogs::Show  

FunctionEnd 
Manchut is offline   Reply With Quote
Old 24th February 2013, 18:15   #17
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
Function SerialPageShow
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}

${NSD_CreatePassword} 0 10% 50% 8% ""
Pop $serial1_HWND
nsDialogs::Show
FunctionEnd

Function SerialPageLeave
${NSD_GetText} $serial1_HWND $serial1
${If} $serial1 != "12345"
MessageBox MB_OK "Invalid serial!"
abort
${EndIf}
FunctionEnd


You could have figured this out if you had studied the tutorial. It is extremely clear. Perhaps you need to find someone to translate it into your native language?
MSG is offline   Reply With Quote
Old 24th February 2013, 20:16   #18
Manchut
Junior Member
 
Join Date: Oct 2012
Posts: 21
Maybe is clear but my English is not perfect so i don't understand all words. I use goggle translate but you know... This script work only with one serial, don't be angry but how use your code what you write before?

PHP Code:
${NSD_GetText$serial1_HWND $serial1
${NSD_GetText$serial2_HWND $serial2
${If} $serial1 == ${YourSerial1a}
${
OrIf$serial1 == ${YourSerial1b}
etc...
  
StrCpy $serial1valid yes
${Else}
  
StrCpy $serial1valid no
${EndIf}
${If} 
$serial2 == ${YourSerial2a}
${
OrIf$serial2 == ${YourSerial2b}
etc...
  
StrCpy $serial2valid 'yes'
${Else}
  
StrCpy $serial1valid 'no'
${EndIf}

${If} 
$serial1valid != yes
${OrIf$serial2valid != yes
  MessageBox MB_OK 
"Invalid serial(s)!"
  
abort
${EndIf} 
Manchut is offline   Reply With Quote
Old 24th February 2013, 21:23   #19
Highcoder
Member
 
Join Date: Jan 2011
Posts: 69
Ok i can´t read only longer to this thread...

@MSG: He doesn´t need the code for the custom page only. He need the whole concept for the serial stuff. Code generating & encrypting too.

@Manchut: How do you generate your serials? I ask because the idea of storing (all) serials in a textfile is bad. Because of 2 things:
1. How many serials you will store? 100, 1000? What if you have 1001 Users? Will you provide the first serial twice?
2. The textfile will be unpacked to $pluginsdir during runtime. So the complete textfile with ALL serials in it will be found in the users %temp% folder. Readable for everyone. So why obtain a serial from you (for money) when i can get ALL valid serials for free?

So you have to find another solution. Maybe the Registration Plugin in the NSIS plugin section will help you.

But this will not save your content in the installer to get unpacked anyway. Because you can unpack the content of the installer simply with 7-Zip.
The better way is to integrate the serial stuff in your application you wat to provide and not in the installer...

just my 2 cent
Highcoder is offline   Reply With Quote
Old 24th February 2013, 21:26   #20
bnicer
Senior Member
 
Join Date: Feb 2005
Location: London
Posts: 218
Function SerialPageLeave
StrCpy $n 1
loop:
IntCmp $n 1000 0 0 done
${NSD_GetText} $serial_HWND "serial$n"
StrCmp "serial$n" "12345" match
IntOp $n $n + 1
goto loop
done:
MessageBox MB_OK "Invalid serial!"
abort
match:
FunctionEnd

Not sure this code helps at all in your case, but you should try with a loop to get away from all those ${OrIf} conditions.
bnicer is offline   Reply With Quote
Old 24th February 2013, 23:38   #21
bnicer
Senior Member
 
Join Date: Feb 2005
Location: London
Posts: 218
; your 1 password for everyone is "happy"
; use an md5 generator to encrypt happy
; md5 = 56ab24c15b72a457069c5ea42fcfc640

Var KEY ; happy
ReserveFile "${NSISDIR}\Plugins\md5dll.dll"

; now generate 1000 serials

Function SerialPageLeave
StrCpy $KEY "56ab24c15b72a457069c5ea42fcfc640"
StrCpy $R0 1
loop:
IntCmp $R0 1000 0 0 done
${NSD_GetText} $serial_HWND $R1
md5dll::GetMD5String "$KEY$R0" ; generate 1000 times
Pop $R3
StrCmp $R1 $R3 match
IntOp $R0 $R0 + 1
goto loop
done:
MessageBox MB_OK "Invalid serial!"
abort
match:
FunctionEnd

; your 1000 serials are all different
; to decrypt them you need the key
; you can create a private list with the generated serials, but don't copy it to the $pluginsdir
bnicer is offline   Reply With Quote
Old 25th February 2013, 05:29   #22
bnicer
Senior Member
 
Join Date: Feb 2005
Location: London
Posts: 218
${NSD_GetText} $serial_HWND $R1 -- doesn't need to be in the loop. It can come before.

My mistake.

If you already have a list of serials, ie. 12345, 12346, 12347, here is another option:

Var serial

!macro serials num
StrCpy $serial "1234${num}"
!macroend

Function SerialPageLeave
StrCpy $R0 5
${NSD_GetText} $serial_HWND $R1
loop:
IntCmp $R0 7 0 0 done
!insertmacro serials $R0
StrCmp $serial $R1 match
IntOp $R0 $R0 + 1
goto loop
done:
MessageBox MB_OK "Invalid serial!"
abort
match:
FunctionEnd
bnicer is offline   Reply With Quote
Old 25th February 2013, 08:28   #23
Manchut
Junior Member
 
Join Date: Oct 2012
Posts: 21
Highcoder
1. Last time this patch download about 1000 people. But serials can be repeat.
2. I want use this install program for patch so I thing that many users buy this patch and don't be search temp file to find this file (cash going for website not for me). Registration Plugin is not free and I don't have money to buy ;/


Bnicer thanks so much for codes I have question.

When i try generate your code i have error

1. "!insertmacro: macro "serials_num" requires 0 parameter(s), passed 1!
Error in script "C:\Users\Thom\Desktop\test.txt" on line 123 -- aborting creation process"
!insertmacro serials $R0

2. With code md5 i can't understand this. Where I find this list, i must use ReserveFile to add this file?

Thanks for help and patient
Manchut is offline   Reply With Quote
Old 25th February 2013, 08:33   #24
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
Quote:
Originally Posted by Manchut View Post
Maybe is clear but my English is not perfect so i don't understand all words. I use goggle translate but you know... This script work only with one serial, don't be angry but how use your code what you write before?
Don't worry, I won't get angry. To get your custom page to accept two serials, simply add a second textbox to the page function:
Function SerialPageShow
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}

${NSD_CreatePassword} 0 10% 50% 8% ""
Pop $serial1_HWND
${NSD_CreatePassword} 0 10% 50% 8% ""
Pop $serial2_HWND

nsDialogs::Show
FunctionEnd

That's how nsDialogs works: You add components by adding ${NSD_Create...} macros before you nsDialogs::Show the page.
MSG is offline   Reply With Quote
Old 26th February 2013, 06:58   #25
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
Err oops, the coordinates for the two password fields should of course not be the same:
${NSD_CreatePassword} 0 10% 50% 8% ""
Pop $serial1_HWND
${NSD_CreatePassword} 0 20% 50% 8% ""
Pop $serial2_HWND
MSG is offline   Reply With Quote
Old 26th February 2013, 07:51   #26
Manchut
Junior Member
 
Join Date: Oct 2012
Posts: 21
But this code create two different window so is not good for me...
Manchut is offline   Reply With Quote
Old 26th February 2013, 11:35   #27
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
Then what exactly do you need?
MSG is offline   Reply With Quote
Old 26th February 2013, 11:51   #28
Manchut
Junior Member
 
Join Date: Oct 2012
Posts: 21
I have custom page with place to write password. But still have problem with script. I want put in the install program 100 serials (I can do this manually) who are verified by script. Your script work great but only for one serial, script what put Bnicer for me still don't understandable...
Manchut is offline   Reply With Quote
Old 26th February 2013, 13:48   #29
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
${OrIf} $serial1 == ${YourSerial1b}
^-- that line is where you add more possible serial codes.

Once again, keep in mind that this method is NOT secure at all. It will be very easy to extract all possible serial codes from your installer. (And HighCoder also mentioned that it will be easy to extract your program files from the installer, even if the user doesn't have a serial key.)

Since you are not very experienced with programming, you should find/hire someone who is experienced, so you can get a more secure solution.
MSG is offline   Reply With Quote
Old 26th February 2013, 14:40   #30
bnicer
Senior Member
 
Join Date: Feb 2005
Location: London
Posts: 218
http://nsis.sourceforge.net/MD5_plugin.

Generating a list of serials is easy.

StrCpy $R0 1
loop:
IntCmp $R0 100 0 0 done
md5dll::GetMD5String "$KEY$R0" ; generate 100 times
Pop $R3
DetailPrint "Serial$R0 $R3"
IntOp $R0 $R0 + 1
goto loop
done:

Then copy the text to the clipboard and save the list:

Serial1 41da99a57f72e811faca6dfaaa403a3c
Serial2 d0dccc680767fb0acb2f5df0457c2148
Serial3 2bbf3c130706078ef96ce561841b9a93

For checking user input on your password page, the method is almost the same.

Function SerialPageLeave
; only you know that the key is "happy"
StrCpy $KEY "56ab24c15b72a457069c5ea42fcfc640"
StrCpy $R0 1
${NSD_GetText} $serial_HWND $R1
loop:
IntCmp $R0 100 0 0 done
md5dll::GetMD5String "$KEY$R0" ; generate 100 times
Pop $R3
StrCmp $R1 $R3 match
IntOp $R0 $R0 + 1
goto loop
done:
MessageBox MB_OK "Invalid serial!"
abort
match:
FunctionEnd

=======

You can make an md5 hash as secure as you like by encrypting it again and again with different keys.

Take 56ab24c15b72a457069c5ea42fcfc640 (happy), for instance, and calculate an md5 hash for 56ab24c15b72a457069c5ea42fcfc640+sad. The resulting hash will have two levels of encryption, and should be almost impossible to crack.

Unless somebody read this thread. Therefore always add a few twists and turns.

=======

MSG is right too, somebody can extract the serials from your installer, and the method for generating the serials.
bnicer is offline   Reply With Quote
Old 26th February 2013, 15:08   #31
Manchut
Junior Member
 
Join Date: Oct 2012
Posts: 21
Ok now i better understand all. But when i put and compilation this
PHP Code:
Name "MD5dll Example"
OutFile "keys.exe"
ShowInstDetails show

Section 
StrCpy $R0 1
loop
:
IntCmp $R0 100 0 0 done
md5dll
::GetMD5String "$KEY$R0generate 100 times
Pop $R3
DetailPrint 
"Serial$R0 $R3"
goto loop
done
:
SectionEND 
and install program don't work. I use windows 8 maybe this is problem?
Manchut is offline   Reply With Quote
Old 26th February 2013, 15:27   #32
bnicer
Senior Member
 
Join Date: Feb 2005
Location: London
Posts: 218
ReserveFile "${NSISDIR}\Plugins\md5dll.dll"
Var KEY

Section
StrCpy $KEY "56ab24c15b72a457069c5ea42fcfc640"
StrCpy $R0 1
loop:
IntCmp $R0 100 0 0 done
md5dll::GetMD5String "$KEY$R0" ; generate 100 times
Pop $R3
DetailPrint "Serial$R0 $R3"
IntOp $R0 $R0 + 1
goto loop
done:
SectionEnd

That works on Windows 7.
bnicer is offline   Reply With Quote
Old 26th February 2013, 15:36   #33
Manchut
Junior Member
 
Join Date: Oct 2012
Posts: 21
Great, now work. Thanks so much for help )
Manchut is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump