- NSIS Discussion
- A proper tutorial for password protect?
Archive: A proper tutorial for password protect?
rxs2k5
14th April 2006 18:51 UTC
A proper tutorial for password protect?
Hi pros,
I been searching out but then as I am a noob to this, I am unable to understand how to create a password custom page, the resource in here do not have sufficient tutorials on creating it.
Can anyone create a detail tutorial on Password Custom Page in ModernUI.nsi script or something which can be easily set just by changing the password filled in the example, so that when user starts to load the installer it will prompt for a correct password before proceeding
And More tutorials how you really configure the InstallOptions and .ini files to react with the password custom page.
thanks
rxs2k5
14th April 2006 19:26 UTC
this is one excellent tutorial thanks alot I understand alot from this one.
Thanks alot man Afrow UK your the man, if only there was a better navigation to this resource everyone could have done it.
rxs2k5
14th April 2006 20:10 UTC
Hi, Afrow UK
More questions regarding UserPass.nsi
How do I add more username and password ?
Which files should I be editing ?
Afrow UK
14th April 2006 20:20 UTC
Depends how you want to store the usernames and passwords.
In UserPass.nsi the username and password are hardcoded into the installer with two !defines. If you want more usernames and passwords, add more defines and change the code that compares the inputted usernames and passwords.
-Stu
rxs2k5
14th April 2006 20:43 UTC
I edited the UserPass.nsi a bit but one problem , when I tried the first set , Jeff , blah it did not work, but when I tried the second set , stealth , zero it work.
Could you tell me which part I am wrong in this script
## Include headers
!include MUI.nsh
## Pages
!insertmacro MUI_PAGE_WELCOME
Page Custom passwordPage passwordPageLeave
!define MUI_PAGE_CUSTOMFUNCTION_SHOW showComponents
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
## Password is
!define Password "blah"
!define Username "Jeff"
!define Password1 "zero"
!define Username1 "stealth"
## Control ID's
!define IDC_USERNAME 1210
!define IDC_PASSWORD 1211
!define IDC_USERNAME1 1216
!define IDC_PASSWORD1 1217
## Languages
!insertmacro MUI_LANGUAGE English
## Displays the password dialog
Function passwordPage
!insertmacro MUI_HEADER_TEXT "Enter Username && Password" "Enter your username and password to continue."
PassDialog::InitDialog /NOUNLOAD UserPass
Pop $R0 # Page HWND
GetDlgItem $R1 $R0 ${IDC_USERNAME}
SetCtlColors $R1 0xFF0000 0xFFFFFF
GetDlgItem $R1 $R0 ${IDC_PASSWORD}
SetCtlColors $R1 0x0000FF 0xFFFFFF
PassDialog::Show
FunctionEnd
## Validate password
Function passwordPageLeave
## Pop password & username from stack
Pop $R0
Pop $R1
POP $R2
POP $R3
## A bit of validation
StrCmp $R0 '${Username}' +4 +2
StrCmp $R1 '${Password}' +3
StrCmp $R2 '${Username1}' +4 +2
StrCmp $R3 '${Password1}' +3
MessageBox MB_OK|MB_ICONEXCLAMATION "The username is '${Username}' and the password is '${Password}', fool!"
Abort
## Display the password
MessageBox MB_OK|MB_ICONINFORMATION "The username and password is correct: $R0, $R1!"
FunctionEnd
Function showComponents
## Disable the Back button
GetDlgItem $R0 $HWNDPARENT 3
EnableWindow $R0 0
FunctionEnd
## Just a dummy section
Section 'A section'
SectionEnd
Afrow UK
14th April 2006 20:48 UTC
## Password is
!define Username1 "Jeff"
!define Password1 "blah"
!define Username2 "stealth"
!define Password2 "zero"
...
## Validate password
Function passwordPageLeave
## Pop password & username from stack
Pop $R0
Pop $R1
## A bit of validation
StrCmp $R0 '${Username1}' 0 +2
StrCmp $R1 '${Password1}' Good Bad
StrCmp $R2 '${Username2}' 0 +2
StrCmp $R3 '${Password2}' Good Bad
Bad:
MessageBox MB_OK|MB_ICONEXCLAMATION "The entered username or password is incorrect!"
Abort
Good:
FunctionEnd
-Stu
rxs2k5
14th April 2006 20:59 UTC
hey thanks but something is wrong again, when I enter the first set , Jeff , blah I am able to access the sections but when I enter the second set , stealth,zero it was incorrect and cannot access
## Include headers
!include MUI.nsh
## Pages
!insertmacro MUI_PAGE_WELCOME
Page Custom passwordPage passwordPageLeave
!define MUI_PAGE_CUSTOMFUNCTION_SHOW showComponents
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
## Password is
!define Username1 "Jeff"
!define Password1 "blah"
!define Username2 "stealth"
!define Password2 "zero"
## Control ID's
!define IDC_USERNAME 1210
!define IDC_PASSWORD 1211
## Languages
!insertmacro MUI_LANGUAGE English
## Displays the password dialog
Function passwordPage
!insertmacro MUI_HEADER_TEXT "Enter Username && Password" "Enter your username and password to continue."
PassDialog::InitDialog /NOUNLOAD UserPass
Pop $R0 # Page HWND
GetDlgItem $R1 $R0 ${IDC_USERNAME}
SetCtlColors $R1 0xFF0000 0xFFFFFF
GetDlgItem $R1 $R0 ${IDC_PASSWORD}
SetCtlColors $R1 0x0000FF 0xFFFFFF
PassDialog::Show
FunctionEnd
## Validate password
Function passwordPageLeave
## Pop password & username from stack
Pop $R0
Pop $R1
## A bit of validation
StrCmp $R0 '${Username1}' 0 +2
StrCmp $R1 '${Password1}' Good Bad
StrCmp $R2 '${Username2}' 0 +2
StrCmp $R3 '${Password2}' Good Bad
Bad:
MessageBox MB_OK|MB_ICONEXCLAMATION "The entered username or password is incorrect!"
Abort
Good:
FunctionEnd
Function showComponents
## Disable the Back button
GetDlgItem $R0 $HWNDPARENT 3
EnableWindow $R0 0
FunctionEnd
## Just a dummy section
Section 'A section'
SectionEnd
rxs2k5
14th April 2006 21:03 UTC
solved
StrCmp $R2 '${Username2}' 0 +2
StrCmp $R3 '${Password2}' Good Bad
should be replaced as
StrCmp $R0 '${Username2}' 0 +2
StrCmp $R1 '${Password2}' Good Bad
Afrow UK
14th April 2006 22:39 UTC
Sorry yes it should be. I used the code from your last post as a base.
-Stu
rxs2k5
17th April 2006 16:47 UTC
Hi there Afrow UK
Just wondering,
Is there a way to allow
!define Username1 "Jeff"
!define Password1 "blah"
!define Username2 "stealth"
!define Password2 "zero"
to be in store somewhere or
## A bit of validation
StrCmp $R0 '${Username1}' 0 +2
StrCmp $R1 '${Password1}' Good Bad
StrCmp $R0 '${Username2}' 0 +2
StrCmp $R1 '${Password2}' Good Bad
to be store somewhere instead of being added to the script itself ???
Means It will still be read when the user type in the username and password, but I wish to add something like a database. If I had many many more clients, I will be able to add into it instead of using it again and again on different installers.