°°° password problem °°°

hey there,

I made this tutorial and everything works just fine. But is it possible to use more than one password or not? I tried this:

password = inputName;
if (password == “kirupa”) {
answer = “kirupa is ok!”;
} else {
answer = “Access denied!”;
}
if (password == “lampe”) {
answer = “lampe is ok!”;
} else {
answer = “Access denied!”;
}

but what happened was this: if i fill in “kirupa”, i get acces denied. If i fill in “lampe”, it works (i get “lampe is ok!”).
Is it possible to use two or more passwords?

thanks

You need else if()

[AS]password = inputName;
if (password == “kirupa”) {
answer = “kirupa is ok!”;
} else if (password == “lampe”){
answer = “lampe is ok!”;
} else {
answer = “Access denied!”;
}[/AS]

If password is kirupa, do this, else if password is lampe, do this, else access denied.

store your passwords in an array:

Array.prototype.doCheck = function ( psw )
{
for ( var i=0 ; i<this.length ; i++ ) if ( this* == psw ) return "Access Granted";
return "Access Denied";
}

mypsws = [ "kirupa" , "lampe" , "ahmed" ];

… now, to call the doCheck function, you would do this

answer = mypsws.doCheck("kirupa");
trace(answer);

let me know how that goes

thank you sooo mutch, it works great!

lampe

Nice one there Ahmed, you could also use a for…in loop instead of a standard for loop…

[AS]Array.prototype.doCheck = function(psw) {
for (var i in this) if (this* == psw) return “Access Granted”;
return “Access Denied”;
};[/AS]