SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help with login script!

    I'm using this login script below but when I test it it only allows the second part(red and white) to work but not the first( blue and pink). I mean when I try to login I can't login with the first part, it says invalid id, but with the second part it lets me login. So why does it do that? How can I make it so I can allow more than one login name and pass to work?
    script language="javascript">
    <!--//
    /*This Script allows people to enter by using a form that asks for a
    UserID and Password*/
    function pasuser(form) {
    if (form.id.value=="Blue") {
    if (form.pass.value=="Pink") {
    location="http://sonicfighters.cjb.net/"
    } else {
    alert("Invalid Password")
    }
    } else { alert("Invalid UserID")
    }
    }


    //-->
    </script>
    <script language="javascript">
    <!--//
    /*This Script allows people to enter by using a form that asks for a
    UserID and Password*/
    function pasuser(form) {
    if (form.id.value=="Red") {
    if (form.pass.value=="White") {
    location="http://sonicfighters.cjb.net/"
    } else {
    alert("Invalid Password")
    }
    } else { alert("Invalid UserID")
    }
    }


    //-->

    </script>

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Are both functions on the same page? If so, then since they are on the same page the browser will get confused and choose a function to follow arbitrarily. Combine the two functions into one and you should be ok.

    Have you thought about perhaps putting this function server-side in PHP or ASP? Sticking password info on the client side where anyone can view your source code is not secure and is generally a bad idea.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do I combine them into one?

  4. #4
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Code:
    <script language="javascript" type="text/javascript">
    <!--//
    /*This Script allows people to enter by using a form that asks for a
    UserID and Password*/
    function pasuser(form) {
    //for red box
    if (form.id.value=="Red") { 
    if (form.pass.value=="White") { 
    location="http://sonicfighters.cjb.net/" 
    } else {
    alert("Invalid Password");
    return false;
    }
    } 
    
    //for blue box
    if (form.id.value=="Blue") { 
    if (form.pass.value=="Pink") { 
    location="http://sonicfighters.cjb.net/" 
    } else {
    alert("Invalid Password")
    return false;
    }
    }
    
    if (form.id.value!="Blue" && form.id.value!="Red") {
    alert ("Invalid userID!");
    return false;
    }
    }
    //-->
    </script>
    Edit: Cleaned up some of the code.
    Last edited by vgarcia; Feb 9, 2003 at 11:57.

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Oh I see now. Thanks.

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One problem. It works but when I login it says Invalid User ID and then I click on Ok and it lets me in. Why does it do that?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •