Javascript: Get the Index Value from an Array
<p>This is for a Java script course that Im taking...</p>

<p>I need to create a simple user-login script.  When the page loads a prompt pops up asking for the user name.  If the correct username is entered, another prompt is displayed asking for a password.</p>

<p>If both the username and valid, then you a sucessful message, otherwise you get a failure message.</p>

<p>I've written all of the code, but am having trouble with validating the username and password.
You can see in my code that I'm using two array lists.  One for users and another for passwords.  When I run my code, if I type in the correct username and password for user1, it validates, BUT if I enter user1 and the password for user2, it still validates.</p>

<pre><code>&lt;script type="text/javascript"&gt;
//Input from user
    var userId = prompt("Enter UserID", "");
        userId_lowercase = userId.toLowerCase();


//Username and Password Arrays
    var userIdList = new Array();
        userIdList[0] = "user1";
        userIdList[1] = "user2";
        userIdList[2] = "user3";

    var passwordList = new Array();
        passwordList[0] = "pass1";
        passwordList[1] = "pass2";
        passwordList[2] = "pass3";

//Process input and check for authentication

    //Check for correct userId

        var userIdFound;

        for (index in userIdList) 
        {
            if (userId_lowercase == userIdList[index]) 
            {
                userIdFound = "Y";
                break;
            }
        }

        if (userIdFound == "Y") 
        {
            document.write("&lt;p&gt;" + userId + " was Found&lt;/p&gt;"); ;
            //Check for correct Password
            var password = prompt("Enter Password", "");
            var passwordFound;

            for (index in passwordList) 
            {
                if (password == passwordList[index]) //  This is where I need help, 
                                                     //  how do I say 
                                                     //  "if password is from the passwordList &amp;&amp; it matches the userId index selected"

                {
                    passwordFound = "Y";
                    break;
                }
            }

            if (passwordFound == "Y") 
            {
                document.write("&lt;p&gt;Welcome to the class!&lt;/p&gt;"); 
            }
            else 
            {
                document.write("&lt;p&gt;Error: Password is not valid.&lt;/p&gt;"); 
            }//END Password Check

        } 
        else 

        {
            document.write("&lt;p&gt;" + userId + " was NOT found&lt;/p&gt;"); 
        }//END USERID Check

&lt;/script&gt;
</code></pre>
