Archive: Username/Password Integration


Username/Password Integration
So im building a NSIS installer for one of the servers that im allowing that lets agents bridge their software to my db.

On my PHP form it takes their login/password and stores it then installs with those settings.


Is there a way to do this with NSIS?

Specifically, I would like it to prompt for a username/password in a window just after language setting, then transport that to one of the installer files.


Any ideas?


nsDialogs/InstallOptions. Or you can use the PassDialog plug-in but nsDialogs may be best.

Stu


Ok so I got the user/pass to store to a variable, now all I need to do is print it to a .php file (it can be text, its just going to need to be there so that it can be found by another person)

FileOpen $9 asim_ini.php w
FileWrite $9 " <?php"
FileWrite $9 " //bridge file created Mon, 29 Jun 2009 15:43:29 -0500 for user $uNameRem"
#FileWrite $9 " $asim_install_dir = "";"
#FileWrite $9 " $bridge_company = "A";"
#FileWrite $9 " $asim_bridge_upload_url = ""
#FileWrite $9 " $asim_bridge_server = ""
#FileWrite $9 " $asim_bridge_pub_key = ""
#FileWrite $9 " $browser_path = ""
#FileWrite $9 " $test_bridge_file_name = ""
#FileWrite $9 " $agent_auth = ""
#FileWrite $9 " $detect_os = ""
FileWrite $9 " //if this is an nt machine but %OS% is custom, uncomment next line and add custom value."
#FileWrite $9 " $custom_nt_os_env = "";"
#FileWrite $9 " $wl_user_name = "$uNameRem";"
#FileWrite $9 " $wl_user_password = "$pWord";"
#FileWrite $9 " $proxy_host = "";"
#FileWrite $9 " $proxy_port = "";//8080 and 3128 are common proxy ports"
#FileWrite $9 " $proxy_user = "";"
#FileWrite $9 " $proxy_pass = "";"
FileWrite $9 " ?>"
FileClose $9

Thats what I have for my filewrite, but 2 things are the problem,

1. Its not writing the file and including it in the install....it doesnt show up in the folder with the install.

2. Im getting some random errors about it wanting 3 parameters instead of 6.

Ideas?


1. Specify a full path.
2. You have some quotes inside quotes. Either escape them using $\ or change the outer quotes to ` or '.

Stu


Specify a full path for which, the

FileOpen $9 asim_ini.php w ?

i.e. FileOpen $9 C:\asim_ini.php w ?


Correct. Otherwise it writes to the working directory (whatever $OUTDIR is).

Stu


Originally posted by Afrow UK
Correct. Otherwise it writes to the working directory (whatever $OUTDIR is).

Stu
Ok, so here is my code. Everythign compiles without errors, but in the install Dir, the asim_ini.php is not showing up.

Am I doing something wrong? I changed the format of my code a bit.

Function asimwrite
!macro WriteLine Line
FileWrite $R0 `${Line}$\r$\n`
!macroend
!define WriteLine `!insertmacro WriteLine`

Push $R0
FileOpen $R0 `$INSTDIR\asim_ini.php` w
${WriteLine} ' <?php'
${WriteLine} ' '
${WriteLine} ' '
${WriteLine} ' $bridge_company = "";'
${WriteLine} ' $asim_bridge_upload_url = "";'
${WriteLine} ' $asim_bridge_server = "";'
${WriteLine} ' $asim_bridge_pub_key = "5740dbb403b4c2c3bd7525e05364785ce84f23bc";'
${WriteLine} ' $browser_path = "C:\\Program Files\\Internet Explorer\\iexplore.exe";'
${WriteLine} ' $test_bridge_file_name = "test_brg.txt";'
${WriteLine} ' $agent_auth = "Y";'
${WriteLine} ' $detect_os = "Y";'
${WriteLine} ' //if this is an nt machine but %OS% is custom, uncomment next line and add custom value.'
${WriteLine} ' $custom_nt_os_env = "";'
${WriteLine} ' $wl_user_name = "$uNameRem";'
${WriteLine} ' $wl_user_password = "$pWord";'
${WriteLine} ' $proxy_host = "";'
${WriteLine} ' $proxy_port = "";//8080 and 3128 are common proxy ports'
${WriteLine} ' $proxy_user = "";'
${WriteLine} ' $proxy_pass = "";'
${WriteLine} ' ?>'
${WriteLine} ' The write File is working!'
FileClose $R0
Pop $R0
FunctionEnd



All I need it to do is to make sure that text is in the .ini text file so that when it is called from another program that file is existant.


Ideas (thanks for all the help!)

Does $INSTDIR exist before you call this function?

Stu


Oh crap im dumb.

Okay so at the end of the install function, just call this function?

What is the code to call a function in NSIS?

Call {lkjsdklfjsd}?


If you looked up Call you'd find out!

Stu


Doing that now!

Thanks for all the help!


God im dumb, it worked.

Wrote the file extremely well.....such a big help.


Now, when I do my username/login, its not writing the proper value that I had stored in the var.

Here is my code,

Var uNameRem
Var pWord

Function myPage
nsDialogs::Create 1018

!insertmacro MUI_HEADER_TEXT "Producer Login" "Please login to the server."
${NSD_CreateLabel} 0 0 300u 48u "To continue with installation you will need to login.$\n$\n$\n$\nPlease enter your producer code and password."
${NSD_CreateLabel} 20u 60u 60u 12u "Producer Code: "
${NSD_CreateText} 80u 58u 150u 12u $uNameRem
Pop $uNameRem
${NSD_CreateLabel} 20u 80u 60u 12u "Password: "
${NSD_CreateText} 80u 78u 150u 12u "" $pWord
Pop $pWord
GetDlgItem $0 $HWNDPARENT 1
SendMessage $0 ${WM_SETTEXT} 0 "STR:Login"
nsDialogs::Show

MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you producer code is $uNameRem and your password is $pWord?" IDYES +2
FunctionEnd


when I call the $uNameRem and $pWord is just gives a big long number rather than what was entered. Is there a more explicit way to call this variable so it displays the correct variable?


That is because they contain the text box control handles not the texts. You need to store the texts in 2 other variables and read the texts using NSD_GetText.

Stu


Im not sure I follow you on this one, is there an example of this somewhere?


There are many examples. The nsDialogs doc shows it quite well too.

Stu


${NSD_CreateLabel} 20u 60u 60u 12u "Producer Code: "
${NSD_CreateText} 80u 58u 150u 12u ""
Pop $uNameRem

${NSD_CreateLabel} 20u 80u 60u 12u "Password: "
${NSD_CreateText} 80u 78u 150u 12u ""
Pop $pWord

${NSD_GetText} $uNameRem $Name
${NSD_GetText} $pWord $Pass


Thats what I have now, the problem is its not storing the information correctly.

I have the vars defined properly, but I have a feeling im missing something minor


You have to get the text in the leave function.

Edit: Also for the two CreateText lines rather than passing an empty string you could pass the two text variables instead so that the user does not have to enter again, but that is up to you.

Stu


Originally posted by Afrow UK
You have to get the text in the leave function.

Edit: Also for the two CreateText lines rather than passing an empty string you could pass the two text variables instead so that the user does not have to enter again, but that is up to you.

Stu
I dont follow you on the leave function....

Function nsDialogsPageLeave

${NSD_GetText} $Text $0
MessageBox MB_OK "You typed:$\n$\n$0"

FunctionEnd



Thats the only example of a leave function I could find

All the examples use a leave function.

Page Custom ShowFunction LeaveFunction

Stu


Got it, thanks for the help afrow.


Next question: How can I convert the password string to an MD5 HASH?


If you search the wiki for MD5 you will find 2 plugins.

Stu


Got that far, just couldnt get it to display the proper hash value;

My code for it is;

Function LoginLeave

${NSD_GetText} $uNameRem $0
${NSD_GetText} $pWord $1
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you SURE your producer code [$0] & password [$1] are correct?" IDYES +2
Crypto::HashData "MD5" "$1"
Pop $2

FunctionEnd


Do I need to add a Get function in order to save that hash data for when it writes to the file?


You should probably use the MD5 plug-in. I'm sure it's smaller in size.

Stu


New Code with MD5 still isnt working....hmmmm

${NSD_GetText} $uNameRem $0
${NSD_GetText} $pWord $1
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you SURE your producer code [$0] & password [$1] are correct?" IDYES +2
md5dll::GetMD5String "$1"
Pop $2



Edit: Do i need to add an output variable to the end of the md5 string?


The Pop $2 puts the return value in $2.

Stu


thats what I thought, but when I display that value when im writing it to my file from earlier, it displays a null value.

Im assuming I need to write a function in that file writing function to call the md5 hash conversion?


got it, thanks for everything afrow


Out of curiosity, for a password field, is there a way to get the text to show in the box as ******** rather than 12345676?


http://nsis.sourceforge.net/NsDialog...ssword_control