View Full Version : Action depends on the password you enter
jhiltabidel
12-04-2007, 05:40 AM
I've been using Autoplay Media 4.0 for several years so this is a major change to get used to. I've downloaded the demo just minutes ago and am considering this purchase for our company.
1. I would like a dialog box to appear on launch so a user can enter a password.
2. Based on the password they enter, I would like an action to occur.
Is this possible and how is it done?
Specifically, if they enter password "1", a network share is mapped (I was going to do this with a batch file) a series of minor changes take place on the system (such as file deletion/creation, also handled with a batch file) and finally a .txt file containing some information is deposited to that mapped network location. (that may also be done with a batch file if necessary)
If they enter a password of "2", the same thing happens basically but the files which are created/deleted are different.
azmanar
12-04-2007, 06:02 AM
Hi,
Step 1. >>> Get the password as a variable, like :
sPassword = Input.GetText("Input1");
Step 2. >>> Use an if ... then loop like :
if sPassword == "1" then
------- do something here------
elseif sPassword == "2" then
------- do something else here----
elseif sPassword =="" then
-------open a dialog box---
end
jhiltabidel
12-04-2007, 06:04 AM
I'll give that a shot. Will this loop endlessly (which is what I would prefer) ?
Is this the actual code I would use: result = Dialog.PasswordInput (as found in the help file)
I have been able to do it with version 4 where after x number of tries, the app closes. But I would like this to stay open until they enter a password.
Thanks,
Joe
azmanar
12-04-2007, 06:54 AM
Hi,
Yes. The variable can be taken like:
sPassword = Dialog.PasswordInput()
Yes. You can leave the thing hanging there until the user enters a correct one. And you can also decide the number of tries by placing a counting mechanism in the loop ( something like below ).
--initial flush
nAttempt = 0;
if sPassword ~="" and sPassword ~="CANCEL" then
nAttempt = nAttempt+1;
if nAttempt = 5 then
Application.Exit();
else
if sPassword == "1" then
------- do something here------
elseif sPassword == "2" then
------- do something else here----
elseif sPassword ~= "1" and sPassword ~= "2" then
sPassword = Dialog.PasswordInput();
end
end
elseif sPassword == "CANCEL" then
Application.Exit();
elseif sPassword == "" then
sPassword = Dialog.PasswordInput()
end
--------------------------
Something to that effect above. I havent the copy of AMS on this PC, so I couldnt test for errors in the loop. But I hope it gives you some useful points.
jhiltabidel
12-04-2007, 08:30 AM
Man, that's great. This is what I have so far:
password = Dialog.PasswordInput("Please call the Help Desk at ext. 3277", "Enter your Deployment Code:", MB_ICONQUESTION);
-- test area start
--initial flush
attempt = 0;
if password ~="" and password ~="CANCEL" then
attempt = attempt+1;
if attempt = 5 then
Application.Exit();
else
-- test area end
if (password == "derek") then
File.Open("AutoPlay\\Docs\\derek.bat", "", SW_SHOWNORMAL);
end
if (password == "dad") then
File.Open("AutoPlay\\Docs\\joe.bat", "", SW_SHOWNORMAL);
end
The part in red gets flagged upon syntax check: 'then' expected near '='
I'm too novice at script writing to understand what it's asking me to do.
Thanks,
Joe
azmanar
12-04-2007, 09:03 AM
Hi,
Its asking for another equal sign, which I missed. :eek:
Should be >> if attempt == 5 then
Expect more errors because I noticed you missed a few things as well.
> You need to close if loops with end.
> You need to use elseif to present options.
jhiltabidel
12-04-2007, 10:16 AM
Thanks again! This is my code so far:
password = Dialog.PasswordInput("Please call the Help Desk at ext. 3277", "Enter your Deployment Code:", MB_ICONQUESTION);
-- test area start
--initial flush
Attempt = 0;
if password ~="" and password ~="CANCEL" then
Attempt = Attempt+1;
if Attempt == 500 then
Application.Exit();
else
-- test area end
if (password == "derek") then
File.Open("AutoPlay\\Docs\\derek.bat", "", SW_SHOWNORMAL);
end
if (password == "dad") then
File.Open("AutoPlay\\Docs\\joe.bat", "", SW_SHOWNORMAL);
end
elseif password ~= "1" and password ~= "2" then
password = Dialog.PasswordInput();
end
end
-- more test area start
elseif password == "CANCEL" then
Application.Exit();
elseif password == "" then
password = Dialog.PasswordInput()
end
-- more test area end
The read area being flagged again:
Line=17: 'end' expected (to close 'if' at line7) near 'elseif'
Can you shed some light on that one?
Thanks again,
Joe
jhiltabidel
12-04-2007, 09:56 PM
This is what I have and it seems to work well with one exception: after 2 incorrect password entries, the password prompt simply goes away. I'm trying to get it to annoyingly continue to prompt for a password until a valid password is entered. I don't want some to just click cancel and get out of entering the password. Any suggestions?
sPassword = Dialog.PasswordInput("Please call the Help Desk at ext. 3277", "Enter your Deployment Code:", MB_ICONQUESTION);
--initial flush
nAttempt = 0;
if sPassword ~="" and sPassword ~="CANCEL" then
nAttempt = nAttempt+1
if nAttempt == 5 then
Application.Exit();
else
if sPassword == "1" then
File.Open("AutoPlay\\Docs\\derek.bat", "", SW_SHOWNORMAL);
elseif sPassword == "2" then
File.Open("AutoPlay\\Docs\\joe.bat", "", SW_SHOWNORMAL);
elseif sPassword ~= "1" and sPassword ~= "2" then
sPassword = Dialog.PasswordInput("Please call the Help Desk at ext. 3277", "Enter your Deployment Code:", MB_ICONQUESTION);
end
end
elseif sPassword == "CANCEL" then
Application.Exit();
elseif sPassword == "" then
sPassword = Dialog.PasswordInput("Please call the Help Desk at ext. 3277", "Enter your Deployment Code:", MB_ICONQUESTION);
end
azmanar
12-05-2007, 02:22 AM
Joe,
Try look at a sample I have. Download and see how it works.
www.azman.info/ams/Password.apz
Then customize it.
jhiltabidel
12-05-2007, 07:19 AM
That's about 99% of it, looks great! If you enter the wrong password, however, it just craps out and stops at page1 without prompting for the password again. I was working on a "while" statement when you posted this which looks like a much better route! Thanks for your help! I'll continue to look at the code today but if you know it's an easy fix and wouldn't mind sharing, I'd be grateful.
Thanks,
Joe
azmanar
12-05-2007, 08:21 AM
Joe,
Yes, it will crap out after 1 wrong entry. Thats why I reinitiate everytime after each entry by routing it to page 1. Thus it will not crap out. Evenso, I consider this as poor control.
Another alternative is to have a welcome page with a little START button. Everytime you click the START button, the Dialog Prompt will reinitiate.
There is however another alternative for password entry. You can use Input Object instead of using Dialog.PasswordInput. The Input Object is placed on the welcome page and a small button GO to click.
What you need to do is to set the Input Object property InputStyle to password mode so that all entries are seen as asterisks *.
Either way, you have better control.
Good luck !!!
jhiltabidel
12-05-2007, 08:54 AM
Ahhh, different kind of crap out. Your code was still working fine and crapping out exactly when it should -- by notifying the user that the password was incorrect and they had x number of tries remaining. But for some reason when I copied/pasted the code into a different project, it didn't work the same. Newbie error on my side. It's working exactly perfectly now and I truly appreciate your help!
Here is my final code aside from some minor additions I will make to the batch files.
sPassword = Dialog.PasswordInput("Image must be validated", "Please enter your deployment code:", MB_ICONQUESTION);
if sPassword ~="" and sPassword ~="CANCEL" then
if sPassword == "derek" then
File.Open("AutoPlay\\Docs\\derek.bat", "", SW_SHOWNORMAL);
elseif sPassword == "joe" then
File.Open("AutoPlay\\Docs\\joe.bat", "", SW_SHOWNORMAL);
-- only way to cancel window start
elseif sPassword == "****" then
Application.Exit(0);
-- only way to cancel window end
elseif sPassword ~= "derek" and sPassword ~= "joe" then
nAttempt = nAttempt+1;
Dialog.Message("Error", "Number of Attempts : "..""..nAttempt.." of 1 million allowed", MB_OK, MB_ICONEXCLAMATION);
if nAttempt == 1000000 then
Application.Exit();
else
Page.Jump("Page1");
end
end
elseif sPassword == "CANCEL" then
Page.Jump("Page1");
elseif sPassword == "" then
Page.Jump("Page1");
end
Thanks,
Joe
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.