Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple Pimple Password

    Alright, I'm a JavaScript noob, and I was hoping someone could help me with this password script. Hard as I've tried, I can't find a JavaScript password protection program other than login gates which provide next to no protection since a user can type the destination page in his URL bar (e.g. if you require a password to get into happy.html they can simply skip the password gate and type /happy.html in the end of their URL bar). I want one that triggers on an onLoad event. I know this involves revealing the password in the source code, but I'm ok with that since I have a source code encrypter that translates source code to ASCII character numbers (%32 = space etc) and anti-right click script, and the people I'm dealing with aren't exactly the most computer-savvy group you ever saw (but they WILL figure it out if I don't use an onLoad).
    Here's what I've come up with. Nothing happens when the page loads, and Mozilla doesn't show any errors in the JavaScript Console:
    Code:
    <SCRIPT LANGUAGE="JavaScript">
    function pass() {
      var password = prompt('What is the password?');
      var correctpass = 'ak47';
      if ( password != correctpass ) {
        alert 'Wrong!';
        window.location = 'http://www.yahoo.com';
      }
      else {
        alert 'Right';
      }
    }</SCRIPT>
    Of course the script is triggered with a normal <BODY onLoad="pass()">


    What's wrong and does anybody know of a script that does this?

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Your alerts are missing the '(' and ')'
    Code:
    <SCRIPT LANGUAGE="JavaScript">
    function pass() {
      var password = prompt('What is the password?');
      var correctpass = 'ak47';
      if ( password != correctpass ) {
        alert('Wrong!');
        window.location = 'http://www.yahoo.com';
      }
      else {
        alert('Right');
      }
    }</SCRIPT>

  • #3
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    And what if they have Javascript disabled or look at your source code?


  •  

    Posting Permissions

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