Password Protecting A File

[Total: 0    Average: 0/5]

This uses a simply password,prompt pair to ask the user for the password.

Body Code:

Password is "password"
<BR>(lowercase no quotes)
var password="password";
var answer="Please enter Password here:"; 
var counter=3; // max tries
var msg = "This page is password protected!";
function getPassword() {
  var _status = false;
  for (var i=0;i<counter;i++) {
    answer = prompt(msg, answer);
    if (answer == password)
	  _status = true;
	if (answer == null)
	  i=counter; // user hit cancel - send them away.
  if (!_status) {
     alert("You had your chance!nGo Learn Some JavaScript!");
getPassword(); // go get the password!

Times Viewed: 1

Leave a Reply

Your email address will not be published. Required fields are marked *