Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryWebsite Development and Maintenance

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Easy Password Access Script

The concept is deceptively simple. Yet, the protection is as good as having hidden file names on the server.

The site visitor types a password in a form.

If it is the correct password, JavaScript will redirect the browser to the protected web page. If it's an incorrect password, the browser redirects the browser to a different location, possibly a 404.

What's deceptively simple is that the password is part of the protected web page file name.

Yet, there is no hint or whisper in the JavaScript of what that file name is. Everybody but you and the people with the password are in the dark about what the file name is.

Here is the JavaScript.

<script type="text/javascript" language="JavaScript">
<!-- Copyright 2005 Bontrager Connection, LLC
// Three customizations:
//
// 1. Between the quotation marks, specify anything that 
//    needs to be in front of the "password" to create 
//    the destination URL. If nothing needs to be in front, 
//    specify two quotation marks with nothing between them.

var FrontOfPassword = "http://example.com/";

// 2. Between the quotation marks, specify anything that 
//    needs to follow the "password" to create the 
//    destination URL. If nothing needs to follow, specify 
//    two quotation marks with nothing between them.

var WhatFollowsPassword = ".html";

// 3. Shall the "password" be converted to all lower case 
//    characters? Specify the answer, either yes or no, 
//    between the quotation marks. (If "no," the "password" 
//    will be case-sensitive.)

var LowerCasePassword = "yes";

function PasswordAccess(v) {
LowerCasePassword = LowerCasePassword.toLowerCase();
if(LowerCasePassword.substr(0,1) == 'y') { 
	v = v.toLowerCase();
	}
location.href = FrontOfPassword + v + WhatFollowsPassword;
return false;
}
//-->
</script>
// end of script

The JavaScript takes the password provided by a form and constructs a URL with it. It then redirects the browser to the constructed URL.

You'll notice that the JavaScript has a place to specify what should come before and after the password the user provides. Also, you can specify whether or not to turn the password into lower case.

Here is a form that can be used with the above JavaScript.

<form>
Password: 
<input 
   type="password" 
   name="pw" 
   size="17">
<input 
   type="submit" 
   onclick="return PasswordAccess(this.form.pw.value);">
</form>

With the customization as provided in the above JavaScript, and if password "Jupiter" was typed into the form, the browser would be redirected to URL http://example.com/jupiter.html.

This is not military grade access restriction.

It does, however, provide a measure of protection about equal to having hidden web page file names. In either case, unauthorized access attempts are reduced to guessing what the file names are.

With a bit of tweaking, the JavaScript and form could be used for a dual password system, where two passwords need to be provided, each correct, in order to gain access.

The two passwords could be combined for a web page file name. Or, one of the passwords could be for a directory name and the other for a file name.

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC