Skip to content
⌘ NSIS Forum Archive

Username/Password Integration

29 posts

ryanpager#

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?
Afrow UK#
nsDialogs/InstallOptions. Or you can use the PassDialog plug-in but nsDialogs may be best.

Stu
ryanpager#
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?
Afrow UK#
1. Specify a full path.
2. You have some quotes inside quotes. Either escape them using $\ or change the outer quotes to ` or '.

Stu
ryanpager#
Specify a full path for which, the

FileOpen $9 asim_ini.php w ?

i.e. FileOpen $9 C:\asim_ini.php w ?
ryanpager#
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!)
ryanpager#
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}?
ryanpager#
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?
Afrow UK#
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
ryanpager#
${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
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
ryanpager#
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
ryanpager#
Got it, thanks for the help afrow.


Next question: How can I convert the password string to an MD5 HASH?
ryanpager#
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?
ryanpager#
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?
ryanpager#
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?
ryanpager#
Out of curiosity, for a password field, is there a way to get the text to show in the box as ******** rather than 12345676?