PDA

View Full Version : Multiple IF statements


Gabis
12-29-2005, 03:05 PM
Hey everyone. What I'm trying to do is create a button that when clicked:

a)prompts the user to enter a password(using Dialog.Input not PasswordInput)

b)Generates an MD5 string for the password and compares it with 7 other MD5 strings

c)depending on the MD5 string returned, performs a specific action

d)if the MD5 generated by the user input does not match any of the 7 other strings, pops up a message telling them the password was incorrect.

I accomplished a, b and c with relative ease, but the use of multiple "if" statements disallows me to use an "else" statement(or so I think is the problem). The reason for this is to install specific language files onto the users computer for my app. For security reasons, only specific users should be able to install/use specific language files and creating an install for each language would be a giant pain in the butt. The files will be stored in pw-protected ZIP's. I know this isnt the most secure thing in the world, but most of the users arent all that computer literate so its good enough for our purposes.

the script is below, note at this time with successful password input I only bring up a dialog box telling me which was entered. This is just for testing purposes. Also for testing purposes, I have only made if statements for 4 of the 7.

function lang_pw()
-- the MD5 strings for passwords by language
French_MD5 = "2ed6ab3d9b07c9a2f8ef51e913fae686"
Italian_MD5 = "6b74b87b7e2b049604ad96c59c36b42f"
Spanish_MD5 = "90ef5e6d211ded4e06dda0d265649e2b"
Russian_MD5 = "b8003391845c34bae900086c90656b3e"
Polish_MD5 = "880388188c719d0de116ce411919fb2f"
German_MD5 = "be66863ed1ecaf17935914f3ad5f2485"
Port_MD5 = "337f9174218c70f5a663cc2e24032898"
-- prompt the user to enter password
user_password = Dialog.Input("Password", "Please enter the password provided to you:");

-- Calculate MD5 from user password
user_password_md5 = Crypto.MD5DigestFromString(user_password);

-- Compare the users password with language passwords
if user_password_md5 == French_MD5 then French_Install = Dialog.Message("French!", "You have entered the french pw", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1); end
if user_password_md5 == Italian_MD5 then Italian_Install = Dialog.Message("Italian!", "You have entered the Italian password", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1); end
if user_password_md5 == Spanish_MD5 then Spanish_Install = Dialog.Message("Spanish!", "You have entered the Spanish password", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1); end
if user_password_md5 == Russian_MD5 then Russian_Install = Dialog.Message("Russian!", "You have entered the Russian password", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1); end
end

Worm
12-29-2005, 03:17 PM
Use elseif:


if YourConditon1 then
--first condition
elseif YourCondition2 then
--second condition
elseif YourCondition3 then
--third condition
else
--anything else
end

Gabis
12-29-2005, 03:20 PM
ahhhh, i knew this had to be really simple. Im just really really new to scripting in general. Thanks alot Worm.

Worm
12-29-2005, 03:22 PM
No problem. It can be a bumpy ride sometimes when you're starting out. The road smoothes out dramatically after you driven for a while :)

yosik
12-29-2005, 08:41 PM
And especially when you have "smoothers" along the way to help you.... Right Worm? ;)

Yossi

Worm
12-29-2005, 09:18 PM
Ya mon! Fer Sure :yes

Intrigued
12-29-2005, 09:25 PM
Ya mon! Fer Sure :yes

Hey! That's my own personal dialect. You dun'did stolenz it furm me!

;)

azmanar
12-31-2005, 12:55 PM
Use elseif:


if YourConditon1 then
--first condition
elseif YourCondition2 then
--second condition
elseif YourCondition3 then
--third condition
else
--anything else
end


Worm,

Don't we have the switch-case-break condition function? I can't find examples on it.

Any leads?

Worm
12-31-2005, 05:35 PM
Nothing like that in LUA. I've looked and found some functions that do essentially the same, but it was just as easy to use If/ElseIf

azmanar
12-31-2005, 05:50 PM
Nothing like that in LUA. I've looked and found some functions that do essentially the same, but it was just as easy to use If/ElseIf

Hi,

Thank you for pointing out clearly.

By the way, I tested your LuaCom Web Server engine. Will it grow and morphed into a PHP5 Engine in AMS suite?

Worm
12-31-2005, 10:24 PM
Not on my watch... I was only playing around with a new toy Brett gave us. More trying to figure out how it worked rather than make a "real" app.