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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    3
    Thanked 0 Times in 0 Posts

    How to modify simple password script

    I am using the simple password script from http://www.allwebco-templates.com/su...ect_simple.htm where the password is contained in the header script.
    I need to change the password, e.g. from Jan to Feb to Mar to Apr etc.
    How could I modify the script to contain the list of passwords, and have it automatically utilise/apply the correct password for the current month?
    To a non-javascript person like me this seems like it should be simple.....
    Can anyone please suggest a solution?
    Thanks muchly in advance.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,915
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Code:
    <script type="text/javascript">
    var months=["January","February","March","April", "May", "June","July","August","September", "October", "Novemeber","Decemeber"];
    var currentMonth = new Date().getMonth();
    var password = months[currentMonth];
    alert (password);
    </script>
    Instead of the names of the months you could have different passwords. But any kind of Javascript password script is hopelessly insecure as the user can see the password simply with View Source.
    And how will your users know the correct password for the current month?

    You can get better security by naming your protected page "password.html" (obviously password is something else cryptic like amg67ves), and then redirecting to the page which is the password which the user has entered +.html. Then the name of the protected page is not visible. Incorrect passwords receive a 404 error.


    "His lack of education is more than compensated for by his keenly developed moral bankruptcy." - Woody Allen - US movie actor, comedian, & director (1935 - )
    Last edited by Philip M; 01-13-2012 at 12:14 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    kiwibrian (01-13-2012)

  • #3
    Regular Coder nomanic's Avatar
    Join Date
    Feb 2009
    Location
    United Kingdom
    Posts
    255
    Thanks
    9
    Thanked 33 Times in 33 Posts
    at the top of your page you have -

    Code:
    <script language="JavaScript" type="text/javascript">
    <!--- PASSWORD PROTECTION SCRIPT
    
    function TheLogin() {
    
    var password = 'pepper';
    
    if (this.document.login.pass.value == password) {
      top.location.href="correct.html";
    }
    else {
      location.href="incorrect.html";
      }
    }
    
    
    // End hiding --->
    </script>
    change this to -

    Code:
    <script language="JavaScript" type="text/javascript">
    <!--- PASSWORD PROTECTION SCRIPT
    
    function TheLogin() {
    
    var d=new Date();
    var month=new Array(12);
    month[0]="January";
    month[1]="February";
    month[2]="March";
    month[3]="April";
    month[4]="May";
    month[5]="June";
    month[6]="July";
    month[7]="August";
    month[8]="September";
    month[9]="October";
    month[10]="November";
    month[11]="December";
    
    var password = month[d.getMonth()];
    
    if (this.document.login.pass.value == password) {
      top.location.href="correct.html";
    }
    else {
      location.href="incorrect.html";
      }
    }
    
    
    // End hiding --->
    </script>
    change the values of January-December to the passwords you want for each month
    in this example the password for January is January
    <DmncAtrny> I will write on a huge cement block "BY ACCEPTING THIS BRICK THROUGH YOUR WINDOW, YOU ACCEPT IT AS IS AND AGREE TO MY DISCLAIMER OF ALL WARRANTIES, EXPRESS OR IMPLIED, AS WELL AS DISCLAIMERS OF ALL LIABILITY, DIRECT, INDIRECT, CONSEQUENTIAL OR INCIDENTAL, THAT MAY ARISE FROM THE INSTALLATION OF THIS BRICK INTO YOUR BUILDING."
    <DmncAtrny> And then hurl it through the window of a Sony officer
    <DmncAtrny> and run like hell

    Portfolio, Tutorials - http://www.nomanic.biz/

  • Users who have thanked nomanic for this post:

    kiwibrian (01-13-2012)

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,915
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    <script language=javascript> is long deprecated and obsolete. Use <script type = "text/javascript">.
    The <!-- and //--> comment (hiding) tags have not been necessary since IE3 (i.e. since September 1997). If you see these in some published script it is a warning that you are looking at ancient and perhaps unreliable code.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    kiwibrian (01-13-2012)


  •  

    Posting Permissions

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