Results 1 to 6 of 6

Thread: Java Script Password Code

  1. #1
    Join Date
    Nov 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Script Password Code

    I am having a problem with my code. It works fine on my computer but as soon as I upload it to the server my Login wont work.

    I know using JavaScript is the furthest from secure but that's okay, I am not worried about it I just need my code fixed. Please help!!

    <html>
    <HEAD>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css">
    <!--
    .style13 {
    color: #CC66CC;
    font-weight: bold;
    }
    .style16 {font-size: 18px}
    .style22 {font-size: 16px}
    -->
    </style><BODY>
    <center>
    <p><img src="ORIGINAL LOGO.JPG" alt="Crystal Boutique" width="300" height="100" longdesc="http://www.x.com"></p>
    <p class="style10"><font size="5" face="Perpetua"> <span class="style13">Please Sign In!</span></font></p>
    <p class="style10">&nbsp;</p>
    </center>
    <script type="text/javascript">
    function submitentry(){
    loggedin=false;
    username="";
    password="";
    username=prompt ("Username:","");
    username=username.toLowerCase();
    password=prompt ("Password:","");
    password=password.toLowerCase();

    -->Enter Username/Password Below <--
    if (username=="ashley00" && password=="2838") {
    loggedin=true;
    window.location="http://216.105.55.115/html/cbreps.html";
    }
    if (username=="evi01" && password=="2594") {
    loggedin=true;
    window.location="http://216.105.55.115/html/cbreps.html";
    }
    if (username=="kristen02" && password=="6510") {
    loggedin=true;
    window.location="http://216.105.55.115/html/cbreps.html";
    }
    -->Enter Username/Password Above <--

    if (loggedin==false){
    alert("Sorry! Invalid Login Information!")
    }
    }
    </SCRIPT>

    <center>
    <form>
    <input type="button" value="Sign In!" onClick="submitentry()">
    </form>
    </center>
    <p>&nbsp;</p>
    <p align="center">&nbsp;</p>
    <p align="center" class="style16"><span class="style9 style22"><font face="Perpetua">If you are having problems logging in click <a href="mailto:x@comcast.net">here</a> to report it.</font> <font face="Perpetua"><br>
    Click <a href="http://www.x.com">here</a> to return to main page.</font><font face="Perpetua"></font></span> </p>
    </center>
    </body>
    </html>

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Javascript cannot provide any security measures for you, so trying to capture a username / password login combination is really just a waste of storage and bandwidth.

    If you have something that needs to be secured with a username / password I suggest you look into some type of server-side programming language like PHP

  3. #3
    Join Date
    Nov 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Does that mean that there is no way possible for my code to work? And if that is true why is it working when I view it on my computer and then stops working when I upload it to the server?

    I am not experienced with PHP, only JavaScript and HTML.

    Can someone please help me. Like I said I am not worried about security at all! Thank you!

  4. #4
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    Try:
    Code:
    window.location.href = "http://216.105.55.115/html/cbreps.html";
    Code:
    <input type="button" value="Sign In!" onclick="submitentry()">
    (Note the lowercase onclick.)

    Code:
    //adding the keyword var
    var loggedin = false;
    var username = "";
    var password = "";
    Make these comments by adding // to their beginning!
    Code:
    //-->Enter Username/Password Below <--
    and the
    Code:
    //-->Enter Username/Password Above <--
    Lowercase your </SCRIPT>
    Code:
    </script>
    /////////////

    Not sure if these will help, but you can try.
    Trinithis

  5. #5
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by unforgettablewebdesigns View Post
    Does that mean that there is no way possible for my code to work?
    security is not the reason that it wont work, it just means that anyone can view it, they would just need to look at the source to find out the url of the redirect.

    And if that is true why is it working when I view it on my computer and then stops working when I upload it to the server?
    good question but on your local machine you are redirecting to another file on the same computer, you arent trying to redirect the script somewhere.

    I am not experienced with PHP, only JavaScript and HTML.
    thats the good thing about the web there are a vast array of tutorials on noth only javascript, html, php, but all other programming languages.

    Quote Originally Posted by Trinithis View Post
    Code:
    <input type="button" value="Sign In!" onclick="submitentry()">
    (Note the lowercase onclick.)
    that is case-insensitive, although personally I believe all lowercase is better semantics.

    Code:
    //adding the keyword var
    var loggedin = false;
    var username = "";
    var password = "";
    again not required, although in this case certainly much better coding technique / semantics.
    Javascript is a (very very) loosely typed language pretty much accepting any case and improper technique... which is why many people have been able to take advantage of its features and turn what can be a very helpful and user-experience benefit turns into frustration and anxiety for the web and computers in general

    Like I said I am not worried about security at all!
    then why bother with the username / password?

    I believe your problem is that the script isnt being initiated to begin with, I still strongly suggest that you use PHP or some other type of server-side programming language for securities sake, but here is a little script.

    Code:
    <script type="text/javascript">
    function getUserAccess()
    {
         var user = prompt("Enter Username:", "").toLowerCase;
         var pass = prompt("Enter Password:", "").toLowercase;
         var okay = false;
    
         switch(user)
         {
              case _user1_:
                   if(pass == "_pass1_") { okay = true }
                   break;
              case _user2_:
                   if(pass == "_pass2_") { okay = true }
                   break;
              case _user3_:
                   if(pass == "_pass3_") { okay = true }
                   break;
              default:
                   okay = false;
                   break;
         }
    
         if(okay) 
         {
    
    Edit: window.location.href="http://216.105.55.115/html/cbreps.html";
    } else { return alert("Incorrect Login Information"); } } </script>
    where the text in blue corresponds to the your allowable values
    that goes in your <head> tag.

    then in the body declaration you would put
    <body onload="getUserAccess()">


    that way will provide prompts for the user to put in information, if you wished them to see the page, and use a form you could use the same function with just a few slight modifications... but I will get to that if its somethign you are interested in
    Last edited by boogyman; 11-14-2007 at 06:30 PM. Reason: missed ending quotation mark

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •