www.webdeveloper.com
Results 1 to 5 of 5

Thread: Javascript html help

  1. #1
    Join Date
    Jan 2013
    Posts
    5

    Javascript html help

    Hey everyone, I've been working on a little password/username program to grab a username, make sure the password matches then it grant you access to a html page.(Just practice purpose only)

    Anyone know where I should put my html? Does it go after the javascript like in the code I provided below? Havn't really tried html and javascript together yet. I'm just hoping when the prompt comes up that the background html is blank, then when access is granted the page loads, if not then it will re-direct you to google.

    Any help would be appreciated.





    <!DOCTYPE html PUBLIC "-W3C//DTD XHTML 1.0 Transistional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html>
    <head>
    <link type="text/css" rel="stylesheet" href="stylesheetqqq.css"/>
    </head>
    <title>
    Java Test
    </title>
    <body bgcolor="silver">

    <script type="text/javascript">

    var user_name, password, passed = false;
    for(var i=1; i<= 3 && passed == false; i++)
    {
    user_name = prompt ("Please enter your username: ");
    password = prompt ("Please enter your password: ");

    passed = ( (user_name=="John123") && (password== "helloworld") );
    } // end of loop after 3 tries *OR* if passed is true

    if ( passed )
    {
    alert("Welcome to the site, " + user_name + ".");

    } else {
    location.href = "http://www.google.com";
    }

    </script>

    <div class="header">Welcome... </div>
    <div class="menu"> <a href="http://www.alexistexas.com/">Home</a> &middot; <a href="http://en.wikipedia.org/wiki/Alexis_Texas">About</a> &middot; <a href="http://www.pornhub.com/video/search?search=alexis%2Btexas">Videos</a> &middot; <a href="https://www.google.ca/">Links</a> &middot; <a href="https://www.google.ca/">Contact</a> &middot;
    </div>

    <p> Welcome John123 to your home page. </p>

    </body>
    </html>

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,262
    So what is to keep anyone from doing a left-click with the mouse to view the source code
    and seeing the user name as 'John123' with a password of 'helloworld'?

    Not a very secure method to use JS to keep anyone from your secret sites.

    BTW, you should use [ code] and [ /code] tags (without the spaces)
    to highlight your script on the forum to make it easier to view, copy and test
    by the forum viewers.

  3. #3
    Join Date
    Jan 2013
    Posts
    5
    Quote Originally Posted by JMRKER View Post
    So what is to keep anyone from doing a left-click with the mouse to view the source code
    and seeing the user name as 'John123' with a password of 'helloworld'?

    Not a very secure method to use JS to keep anyone from your secret sites.

    BTW, you should use [ code] and [ /code] tags (without the spaces)
    to highlight your script on the forum to make it easier to view, copy and test
    by the forum viewers.
    Ya, I realize that. It's just for practice, i'm just getting into programming. Just trying to try out some new things.

  4. #4
    Join Date
    Jan 2013
    Posts
    5
    Do you know what would be a secure way language wise if I did choose to go around doing something like that?

  5. #5
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,262
    Quote Originally Posted by dice93 View Post
    Do you know what would be a secure way language wise if I did choose to go around doing something like that?
    Yes, don't use JavaScript.
    Use some server-side code for any real security requirements.

    If you still want to use JS then search this forum for a number of pseudo-secure JS solutions.
    Google and Bing searches will also give you further examples of non-secure solutions.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles