Results 1 to 8 of 8

Thread: JavaScript:Passwords

  1. #1

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    JavaScript:Passwords

    I know that javascript isn't a reliable source for passwords, but can anyone give me a quick examlpe on how to to a password protected page?


    P.s. most of my users will be stupid people who hardly know how to use IE properly, let alone know what the source means!

  2. #2
    Fanatic Member
    Join Date
    Jan 2005
    Location
    In front of this pc.
    Posts
    580

    Re: JavaScript:Passwords

    Can't help you much with javascript to password protect a webpage but..

    Have you considered using htaccess to password protect directories? Very secure, username/passwords are only stored server side and the server/browser will handle the negotiations for you, and simple to implemente.

  3. #3
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: JavaScript:Passwords

    Have a look at the attatched file.

    That is a very secure example (Well, about as secure as you can get using Javascript).

    Note: I did not write this but, thought you may find it useful

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  4. #4

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    Re: JavaScript:Passwords

    any siimpler ones? something like:
    "if password="easy" then goto www.blahblahblah.com"
    it's not like i'm protecting nuclear silos, or personal documents, just a friends section sort of thing.
    I know no-one in my school who knows about viewing the page source!

  5. #5
    Member
    Join Date
    Mar 2005
    Posts
    56

    Re: JavaScript:Passwords

    Try this out:

    PHP Code:
    <html>
    <
    head>
    <
    script type="text/javascript">
    function 
    passwordProtect()
    {
        var 
    pass "somepassword";
        var 
    protect prompt("Enter the password","");
        if(
    protect != pass)
        {
            
    location.href="http://www.google.com";
        }
        else
        {
            
    location.href="http://www.vbforums.com";
        }
    }
    onload=function(){passwordProtect();}
    </
    script>
    </
    head>
    <
    body>
    </
    body>
    </
    html

  6. #6
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770

    Re: JavaScript:Passwords

    Quote Originally Posted by Brandoe85
    Try this out:

    PHP Code:
    <html>
    <
    head>
    <
    script type="text/javascript">
    function 
    passwordProtect()
    {
        var 
    pass "somepassword";
        var 
    protect prompt("Enter the password","");
        if(
    protect != pass)
        {
            
    location.href="http://www.google.com";
        }
        else
        {
            
    location.href="http://www.vbforums.com";
        }
    }
    onload=function(){passwordProtect();}
    </
    script>
    </
    head>
    <
    body>
    </
    body>
    </
    html
    Now I am going to be a little critical here. That code there seems kind of redundant in that you created a closure to call a function.

    Don't take it the wrong way, lol, it just struck me funny when I saw that.

    ajames, another option might be (if it is available to you), create an ASP page that contains you passwords that you need to authenticate with, then create an HTML form that POSTS the username and password to the ASP page. Doing it this way would keep people from trying to break in.

    Just thought I would mention it.

  7. #7

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    Re: JavaScript:Passwords

    tried asp, but is way to complicated as i have no server (yet), however, the code that was supplied wouldn't let me enter anything in! can someone try and change this?

    thanks in advance.

  8. #8
    Member
    Join Date
    Mar 2005
    Posts
    56

    Re: JavaScript:Passwords

    Hmmm, it's working for me in IE6 and FF1.0.1. Did the prompt pop up at all? Or what happend exactly? Maybe javascript is disabled?

    Good luck;

Posting Permissions

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



Click Here to Expand Forum to Full Width