...

View Full Version : How to modify simple password script



kiwibrian
01-13-2012, 11:19 AM
I am using the simple password script from http://www.allwebco-templates.com/support/S_password_protect_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.

Philip M
01-13-2012, 12:56 PM
<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 - )

nomanic
01-13-2012, 12:57 PM
at the top of your page you have -



<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 -



<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

Philip M
01-13-2012, 01:03 PM
<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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum