JavaScript Password
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Password

  1. #1
    Join Date
    Oct 2012
    Posts
    1

    Cool Password

    Hi I have tried to add another password to the script but it gives me an error what am I doing wrong

    Code:
    <div style="margin-top: 2px">
    <script language="javascript">
    <!--//
    /*This Script allows people to enter by using a form that asks for a
    Password*/
    function pasuser(form) {
    if (form.pass.value=="1234") {
    location="whatever1"
    } else if {
    (form.pass.value=="5678") {
    location="whatever2"
    }
    else {
    alert("Invalid PASSWORD TRY AGAIN")
    }
    }
    //-->
    </script>
    </head>
    <body>
    
    <p >&nbsp;</p>
    
    <form><h2>Login<h2/>
    
    
    
    <input name="pass" type="password">
    <input value="Login" onclick="pasuser(this.form)" type="button">
    <input type="Reset"></form>
    Last edited by PeejAvery; October 27th, 2012 at 10:28 AM. Reason: Added code tags

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,090

    Re: Password

    Couple of things. Because your code is not properly indented, your errors are hidden. Compare yours with mine :

    PHP Code:
    function pasuser(form
    {

        if (
    form.pass.value=="1234"
        {
            
    this.location="http://www.codeguru.com/forums";
        } 
        else if (
    form.pass.value=="5678"
        {
            
    this.location="http://www.codeguru.com";
        }
        else 
        {
            
    alert("Invalid PASSWORD TRY AGAIN");
        }

    You will notice that in yours you have extra {'s inside

    This way of testing passwords are actually IMHO, very bad. I'd have made use of a server side script or even ajax or, a separate javascript script file. These will hide all your passwords from people and bots viewing your page's source.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center