Archive: How to confirm a password in an INI to another field?


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

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;)

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 :)

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


Yes,

Sorry :( I forgot to mention that PassOK & PassNotOK were only labels to you own functions.

Vytautas


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 :)


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 :)


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]

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 :)


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

When you say cancel do yuo mean cancel the installation or just the cancel button on a message box?

Vytautas


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


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


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 ;)


Thats alright, however if you wanted to post the script I could have a look at it and modify it for you?

Vytautas


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.


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

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 :)


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 :)


"$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


BTW, here is one of my recent scripts:
http://myweb.tiscali.co.uk/imker/map...appackager.txt

More info here:
http://dynamic.gamespy.com/~dday/ib3...t=ST;f=2;t=983

-Stu


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.


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