- NSIS Discussion
- How to confirm a password in an INI to another field?
Archive: How to confirm a password in an INI to another field?
vbgunz
18th June 2003 01:34 UTC
How to confirm a password in an INI to another field?
Hello,
I have several fields in an INI in which two are password fields. One field should validate against the other and this is the kind of idea I have...
[Field 9]
ValidateText=[Field 10]
[Field 10]
ValidateText=[Field 9]
This is obviously not the case at trial. I have checked this page but believe its a little more complicated than it should be.
http://nsis.sourceforge.net/archive/....php?pageid=87
I also checked the test.nsi script but that is far off from trying to simply validate one field in an INI to another.
Is this simple? I tried it with and without the square brackets "[]" but I cannot get one field to validate against another... Can someone please help?
Thank you
Vytautas
18th June 2003 04:15 UTC
To compare two passwords with each other use the following commands:
ReadINIStr$0 "$PLUGINSDIR\up.ini" "Field 9" "State"
>ReadINIStr $1 "$PLUGINSDIR\up.ini" "Field 10" "State"
>StrCmp $0 $1 PassOK PassNotOK
>
Vytautas;)
vbgunz
18th June 2003 04:46 UTC
I've tried your snippet and see nothing but problems. Your code looks simple and looks great but just doesn't work. I tried the below code but it fails on every buld.
ReadINIStr $0 "$PLUGINSDIR\UserProfile.ini" "Field 9" "State"
ReadINIStr $1 "$PLUGINSDIR\UserProfile.ini" "Field 10" "State"
StrCmp $0 $1 PassOK PassNotOK
I tried it by nesting it the needed sections but I keep getting the same errors...
Error: could not resolve label "PassOK" in section "RabbitHole" (0)
Error - aborting creation process
Please help me a little further in understanding this. Thank you very much :)
ramon18
18th June 2003 08:15 UTC
omg :p
You are missing the labels to jump after "StrCmp"
Usage: StrCmp str1 str2 label_to_goto_if_equal [label_to_goto_if_not]
so you need to do something like that:
ReadINIStr $0 "$PLUGINSDIR\UserProfile.ini" "Field 9" "State"
ReadINIStr $1 "$PLUGINSDIR\UserProfile.ini" "Field 10" "State"
StrCmp $0 $1 Label_PassOK Label_PassNotOK
Label_PassOK:
MessageBox MB_OK "Password is OK."
; Do other things here if needed
goto Label_EndOfTestPassword
Label_PassNotOK:
MessageBox MB_OK "Password is WRONG!"
; Do other things here if needed
goto Label_EndOfTestPassword
Label_EndOfTestPassword:
; Do other things here if needed
good luck,
Ramon
Vytautas
18th June 2003 08:28 UTC
Yes,
Sorry :( I forgot to mention that PassOK & PassNotOK were only labels to you own functions.
Vytautas
vbgunz
18th June 2003 14:09 UTC
Thank you :)
It works and definitely so very appreciated but can I ask just two questions?
1. How do I get rid of the OK box when the password is right? In other words, if the passwords are correct they simply go ahead with no prompts?
2. When a user hits cancel, how can I avoid prompting them all together? Right now if pass words are wrong and a user hits cancel they can go through a little mean loop...
Otherwise, this really works great, just curious about the other two questions.
Thank you very much :)
vbgunz
18th June 2003 14:16 UTC
I got the first part going so far (Sorry for asking early). The user continues with no prompts of the password is correct. I simply removed the "MessageBox MB_OK "Password is OK." from the "Label_PassOK:"
Very cool indeed, now just how to avoid the password prompt when a user hits cancel?
Thank you so very much for your help :)
Vytautas
18th June 2003 14:17 UTC
For the first question just remove the line:
MessageBox MB_OK "Password is OK."
to remove the need to click OK if passwords are identical.
Vytautas
[edit]
vbgunz was just a second quicker ;)
[/edit]
vbgunz
18th June 2003 14:45 UTC
Thank you Vytautas,
Sometimes I do in fact jump the gun :eek:
How do I kill the wrong password prompt if a user clicks cancel? If it is too much trouble its cool as I was thinking of entering this as the Message Box label...
"I would really like to continue ahead with your order but unfortunately your passwords do not match. Please fix them and I'll stay quiet."
Cool?
hehe, thank you so much for everything, just trying to avoid the wrong password when a user clicks cancel :)
Vytautas
18th June 2003 14:45 UTC
The following code should fix your problem.
Define custom page like this:
Page Custom ShowPassword ValidatePassword
>
The ShowPassword function should setup the custom page as normal.
And finally ValidatePassword Function
ValidatePassword
ReadINIStr$0 "$PLUGINSDIR\UserProfile.ini" "Field 9" "State"
>ReadINIStr $1 "$PLUGINSDIR\UserProfile.ini" "Field 10" "State"
>StrCmp $0 $1 Label_PassOK Label_PassNotOK
Label_PassOK:
; Dothings here if needed
goto Label_EndOfTestPassword
Label_PassNotOK:
>MessageBox MB_OK "Password is WRONG!"
>; Do other things here if needed
Abort
goto Label_EndOfTestPassword
Label_EndOfTestPassword:
; Doother things here if needed
FunctionEnd
>
Note the
Abort command this will not allow the user to go to the next page until the password match.
Vytautas
Vytautas
18th June 2003 14:51 UTC
When you say cancel do yuo mean cancel the installation or just the cancel button on a message box?
Vytautas
vbgunz
18th June 2003 14:57 UTC
I found myself testing the password and when I got happy it found the password wrong and prevented the user from moving ahead I hit cancel on the installer itself...
When I did that I was prompted with Password is Wrong... I hit ok on the message box and hit cancel on the installer again... I was faced with another messagebox... I corrected the passwords and hit cancel but the password scheme didn't like that and said my passwords were wrong...
The only way around it was to fix the passwords, hit next and then hit cancel.
I am working with your newest one now but not sure why to implement a new custom page as I have it already nested into a custom page function...
Thank you Vytautas
Vytautas
18th June 2003 15:01 UTC
You only need to make sure that the custom page definition has the second validation function defined and that if the passwords do not match you abort going to the next page. Sorry if I confused you.
Vytautas
vbgunz
18th June 2003 15:19 UTC
Thank you Vytautas,
As so not to make this confusing I've decided to leave it as is. What are the chances someone gets the password wrong, hits next, hits OK on the prompt and then wants to cancel?
I've inserted this message which I think defines pretty much to the user what must happen if they get caught in the loop.
"Passwords Must Match Before Continuing or Quitting This Application."
I think it is straightforward enough even for those who do not understand the concept of just add water... I hope :)
Thank you Vytautas for everything, I am so far very satisified with it.
Thanks again ;)
Vytautas
18th June 2003 15:23 UTC
Thats alright, however if you wanted to post the script I could have a look at it and modify it for you?
Vytautas
vbgunz
18th June 2003 15:49 UTC
Thank you Vytautas,
Here is a very clean example of how I have it already setup.
If passwords match, the user moves ahead with no prompt. If the users passwords do not match, the user is prompted and sent back to the initial page (this is the preferred method).
If the user gets their passwords wrong and hits next their prompted. But if the user selects cancel to exit the user is sent back to the initial page and is caught in a loop.
The only way the user can escape the loop is if the user makes the passwords match and hits next as cancel will sort of reset the password fields to their initial values and make the passwords wrong again.
Its a little tricky and I appreciate you looking at it a little further. Thank you for your time Vytautas.
Afrow UK
18th June 2003 16:09 UTC
There is a very easy solution to this which would have fixed your problems from the start.
Page Custom PasswordDialog "" "" " - Enter User Password"
Function PasswordDialog
pagetop:
InstallOptions::dialog "$PLUGINSDIR\UserProfile.ini"
Pop $0
StrCmp $0 back pagebottom ;if user clicks back
StrCmp $0 cancel pagebottom ;if user clicks cancel
ReadINIStr $0 "$PLUGINSDIRUserProfile.ini" "Field 9" "State"
ReadINIStr $1 "$PLUGINSDIRUserProfile.ini" "Field 10" "State"
StrCmp $0 $1 PassOK PassNotOK
PassOK:
;whatever here
goto SkipPasswordTest
PassNotOK:
MessageBox MB_OK|MB_ICONEXCLAMATION "Password incorrect!\
$\nYou must re-enter the password." IDOK pagetop
SkipPasswordTest:
;more here
pagebottom:
FunctionEnd
-Stu
vbgunz
18th June 2003 16:23 UTC
Thank you so much for the snippet Afrow UK but unfortunately the script builder stops at the following
"Page Custom PasswordDialog "" "" " - Enter User Password""
and states this as the error...
"Page: CustomError: custom page can not have more than the creator function."
I tried entering the top custom page command like I do the rest. Then I simply inserted the rest of your function by itself in the order of all the rest of the custom pages....
Thank you Afrow UK, I looked forward to your solution :)
vbgunz
18th June 2003 16:32 UTC
Sorry Afrow UK,
It works, just as when I was going over your code you forgot to divide the following...
ReadINIStr $0 "$PLUGINSDIRUserProfile.ini" "Field 9" "State"
ReadINIStr $1 "$PLUGINSDIRUserProfile.ini" "Field 10" "State"
into
ReadINIStr $0 "$PLUGINSDIR\UserProfile.ini" "Field 9" "State"
ReadINIStr $1 "$PLUGINSDIR\UserProfile.ini" "Field 10" "State"
I did that and it works beatifully... I will let you know of any errors I find if any. I hope not, it looks awesome :)
I Thank you and thank Vytautas for everything. You guys are the best :)
Afrow UK
18th June 2003 16:52 UTC
"$PLUGINSDIRUserProfile.ini" is equal to "$PLUGINSDIR\UserProfile.ini" because NSIS will automatically add \ in with those variables ($TEMP, $PROGRAMFILES etc)
Sorry, my code had an extra "" in it...
Page Custom PasswordDialog "" "" " - Enter User Password"
...when it should be...
Page Custom PasswordDialog "" " - Enter User Password"
-Stu
kichik
18th June 2003 16:56 UTC
NSIS doesn't automatically add a back slash for those variables. It automatically removes it. The problem was that Vytautas used [ php ] which removes the back slashes. Using [ code ] is preferred.
Vytautas
19th June 2003 00:43 UTC
Oops!
The problem was that Vytautas used [ php ] which removes the back slashes. Using [ code ] is preferred.
Didn't realise that. Thank you kichik.
Vytautas