Archive: Ask user for username and password and write to variable ?


Ask user for username and password and write to variable ?
  Hi,

I need to ask the user for a username and a password and write that to two variables.
I need to do that because I need a customized shortcut to my software.

So how can I ask the user for a username and a password and save that in a variable?

Thanks in advance


I've found out that a custom page would fit my needs, but I have some trouble making one.

Thats my ini file I've created:

***91;Settings***93;

>NumFields=2

>***91;Field 1***93;
>Type=Text
State=Text
Left=173
Right=296
Top=45
Bottom=58

>***91;Field 2***93;
>Type=Text
State=Text
Left=173
Right=296
Top=62
Bottom=75
>
But I don't have any clue how to create an custom page.
Can someone please help me creating a custom page, which reads the user input from the two textfields.

thanks in advance

You seem to have a good start. But, I'd make Field #2 of type=Password. (and take remove the "state" statement--you probably want them blank.)

If you don't have it yet, I'd suggest downloading HM NIS Edit . It will make creating installoptions pages much easier.

The installoptions docs and examples included with NSIS should give you plenty of info about how to display the page and read the values.

Joel (aka Lobo Lunar) has a DiaglogsEx plugin that might also off another option. But, it's in the form of a dialog, though, not a custom page. (Just depends on your taste.)

It's on the wiki, which I can't get to at the moment, but maybe you can if you're curious...


i will give it a try. thanks a lot


I wonder if it would be worth writing a plugin for this which can display different types of pages from username and password to say serial code boxes.

Some may argue a custom page will work fine, but it has no password security (the password or serial will be stored in the INI file).

-Stu


Interesting thought...
I guess it depends on how secure you need to be. But overall, I think this sounds like an excellenet idea.

Would it be possible for the plugin to integrate with the existing InstallOptions format? This would give the best of both worlds--the designer could still customize their page with the existing installoptions plus could keep things secure. (might require some more brainstorming....)

edit:
Just some more food for thought:
If there was just some way to grab the input string of the password while the user was typing, then you could either save the results in a variable or write them to the INI file in an encrypted form. (The 'encryption' could be done on the fly by a function in the install. It could be something very simple like outputting the characters in hex or more advanced like rearranging the ASCII codes for each character.)


The InstallOptionsEx plugin I noticed has something that would almost work: There is a speical notify for text and password boxes (ONTEXTCHANGE) that is supposed to trigger an event when

when the user changes the state of the text on the control (i.e. when writing) before the change appears on screen.
.

Anyway, like I said, just some things to think about...

Originally posted by Comperio
You seem to have a good start. But, I'd make Field #2 of type=Password. (and take remove the "state" statement--you probably want them blank.)

If you don't have it yet, I'd suggest downloading HM NIS Edit . It will make creating installoptions pages much easier.

The installoptions docs and examples included with NSIS should give you plenty of info about how to display the page and read the values.

Joel (aka Lobo Lunar) has a DiaglogsEx plugin that might also off another option. But, it's in the form of a dialog, though, not a custom page. (Just depends on your taste.)

It's on the wiki, which I can't get to at the moment, but maybe you can if you're curious...
I've tried and tried and tried but it just doesn't work.
I don't need a user/pwd authentification I just need two textfields were the user enters his information and that info is stored in two variables.
So DialogsEx isn't the right thing for me. I've taken a look at the examples too but I can't find anything there that would fit my needs.
Can someone please give me a hint how to create a custom page based on my ini file.
thanks in advance

It's quite simple:


[Settings]
NumFields=2

[Field 1]
Type=Text
Left=173
Right=296
Top=45
Bottom=58

[Field 2]
Type=Password
Left=173
Right=296
Top=62
Bottom=75


You might also want to put some labels on there too.

You need to read the values in the page's Leave function with MUI_INSTALLOPTIONS_READ. There's an InstallOptions example in the Examples\Modern UI folder.

-Stu

I've solved problem already:



Here's the code I use(Taken from some examples):


Temp variable

>!define TEMP2 $R1 ;Temp variable
>.
.
.
!insertmacro MUI_PAGE_WELCOME


>;Things that need to be extracted on startup (keep these lines before any File command!)
;
Only useful for BZIP2 compression
>;Use ReserveFile for your own InstallOptions INI files too!

>ReserveFile "${NSISDIR}\Plugins\InstallOptions.dll"
>ReserveFile "test.ini"

>;Order of pages
Page custom SetCustom ValidateCustom": Testing InstallOptions" ;Custom page. InstallOptions gets called in SetCustom.




Function .onInit

;Extract InstallOptions files
;$PLUGINSDIR will automatically be removed when the installer closes

InitPluginsDir
File/oname=$PLUGINSDIRtest.ini "test.ini"

>FunctionEnd

>Function SetCustom

;Display the InstallOptions dialog

Push${TEMP1}

InstallOptions::dialog "$PLUGINSDIR\test.ini"
Pop ${TEMP1}

Pop ${TEMP1}
>FunctionEnd
>.
.
.
>Section "Software"
;Get Install Options dialog user input

ReadINIStr${TEMP1} "$PLUGINSDIR\test.ini" "Field 1" "State"
ReadINIStr ${TEMP2} "$PLUGINSDIR\test.ini" "Field 2" "State"
>.
.
.

Hi,

I'm sorry; I am an NSIS newbie an I want to create a custom page in which the user is being asked several values, e.g. username etc.
I can generate this custom page easily, using an ini-file called customPage.ini. But at the moment I try to read out the values the user entered I fail. And since I am failing for ~4 hours now, I ask you to explain to me how I can do this. I have studied the examples at the NSIS homepage, I have read (almost) the whole forum, and I have tried to understand and reuse the code example posted above - but failed.
If somebody could explain the last example or write a few lines of code which tell me what is to be done, I would be very thankful!


Alright, I got it. Finally *sigh*