2

Can I set a time limit (for example in 8 hours you have to retype the password)? Here's my very simple javascript:

<SCRIPT language="JavaScript">
    <!--hide
    var password;
    var pass1="x10Kz4iz4ZvEB2wgUBA5otc1";
    var pass2="x10Kz4iz4ZvEB2wgUBA5otc1";
    var pass3="x10Kz4iz4ZvEB2wgUBA5otc1"
    
    password=prompt('Please enter your password to view this page!',' ');
    
    if (password==pass1 || password==pass2 || password==pass3)
      alert('Password Correct! Click OK to enter!');
    else
       {
        alert('Uh oh try again');
        window.location="#";
        }  
    //-->
</SCRIPT>

I have this under the head tag of my HTML text. Thank you :)

OdatNurd
  • 21,371
  • 3
  • 50
  • 68
  • 1
    You know you just need to open console dev for "hack" your password? why don't use a `DB` with session? – Simone Rossaini Oct 07 '20 at 06:52
  • 1
    You can set a cookie to remember that the user has validated and set the expiry of the cookie for 8 hours. – cam Oct 07 '20 at 07:02

1 Answers1

1

This is not really a secure way of protecting your website because anyone can look at the source code of a page and see the Javascript along with the passwords you wrote there.

However, for learning purposes, you might want to learn about setting and getting cookies (How do I create and read a value from cookie?). You can store the time the user logged in, and next time check if it has been eight hours (just compare the time and date of last login to current login time and date).

Also, to get the current time, you should read up on the Javascript Date() function.

astigmatik
  • 134
  • 1
  • 8
  • I coded it so that you can't right-click to look at the Javascript. Are there other ways of getting the Javascript? – Nicholas Davies Oct 08 '20 at 01:29
  • 1
    yes.. they can click the menubar menu and view source.. i forgot the keyboard shortcut but it can also be done.. there is really no easy way to hide javascript – astigmatik Oct 08 '20 at 06:00