Copy link to clipboard
Copied
Hi, I am trying to employ a simple password-only protection to some pages on a website I'm building. I've found what should be the appropriate code at this site: http://javascriptkit.com/script/cut10.shtml
Here is their sample code, password only with a simple popup window to enter the password:
<SCRIPT>
function passWord() {
var testV = 1;
var pass1 = prompt('Please Enter Your Password',' ');
while (testV < 3) {
if (!pass1)
history.go(-1);
if (pass1.toLowerCase() == "letmein") {
alert('You Got it Right!');
window.open('protectpage.html');
break;
}
testV+=1;
var pass1 =
prompt('Access Denied - Password Incorrect, Please Try Again.','Password');
}
if (pass1.toLowerCase()!="password" & testV ==3)
history.go(-1);
return " ";
}
</SCRIPT>
<CENTER>
<FORM>
<input type="button" value="Enter Protected Area" onClick="passWord()">
</FORM>
</CENTER>
The difference is that instead of the centered input = button their sample has on the javascriptkit.com page, I'd like the form to be launched from the click of my Log In button I have in my design – or from clicking on the links for the three pages named: 'membermeetings.htm', 'boardmemberscommittee.htm', 'news_n_photos.htm'. Am I missing a <Form> wrap?
I could also use some tips on where and how much code to put into my <body> section; all of it, part of it?
Here is the code I entered in by adding "Call JavaScript" in behaviors:
onclick="MM_callJS('(\'function passWord() { var testV = 1; var pass1 = prompt(\\\'Please Enter Your Password\\\',\\\' \\\'); while (testV < 3) { if (!pass1) history.go(-1); if (pass1.toLowerCase() == \\"community\\") { alert(\\\'Welcome!\\\'); window.open(\\\'membermeetings.html\\\',\\\'boardmemberscommittee.htm\\\',\\\'news_n_photos.htm\\\'); break; } testV+=1; var pass1 = prompt(\\\'Access Denied - Password Incorrect, Please Try Again.\\\',\\\'Password\\\'); } if (pass1.toLowerCase()!=\\"password\\" & testV ==3) history.go(-1); return \\" \\"; }
Thanks in advance for your help! Brent
Password protecting a folder is done on the webserver. The JavaScript at the top of this thread is insecure, as osgood_ pointed out that anyone can see the password by simply using "View Source".
If you want a secure login for a site, or a section of a site, you need a server-side solution (ie, ColdFusion/Lucee, PHP, JSP, etc.)
V/r,
^ _ ^
Copy link to clipboard
Copied
seems like the most complicated way to lightly protect a web page, or directory,
Have you considered using .htaccess
you can call out and password protect by single pages, or you can put several pages in a directory and give a password to enter that directory
Here are a couple of resources
Comprehensive guide to .htaccess- password protection
Copy link to clipboard
Copied
>Have you considered using .htaccess
Yeah, that was mentioned early on (actually via the host control panel -- not .htaccess -- but essentially the same ) but was rejected by the OP because he thought it applied to the entire website. Nobody informed him that it can be applied to a folder and you can put everything you want to protect into that folder, or used on a single file.
Copy link to clipboard
Copied
bregent wrote:
>Have you considered using .htaccess
Yeah, that was mentioned early on (actually via the host control panel -- not .htaccess -- but essentially the same ) but was rejected by the OP because he thought it applied to the entire website. Nobody informed him that it can be applied to a folder and you can put everything you want to protect into that folder, or used on a single file.
Wasn't it beacause they thought it produced an ugly pop alert box (via the control panel) which couldn't be integrated into the page?
EDITED Re-reading the post it does appear 'I'm only interested in protecting one specific page' in one reply.
I personally would not use the control panel to protect a page beacuse from what I remember it pops open a pretty ugly box outside of the websites widndow, although it will do the job alright.
Copy link to clipboard
Copied
>Wasn't it beacause they thought it produced an ugly pop alert box
>(via the control panel) which couldn't be integrated into the page?
Not sure about that. But you can always integrate an html form with apache restricted access. It's a bit more work. Of course, the advantage is that you can protect resources other than php files.
Copy link to clipboard
Copied
I really need assistance. I'm totally new to this and my client wants me to password protect a folder within their site. I copied the first script at the top of this page and I don't know exactly where to insert the password within the script. Can you assist?
Copy link to clipboard
Copied
Password protecting a folder is done on the webserver. The JavaScript at the top of this thread is insecure, as osgood_ pointed out that anyone can see the password by simply using "View Source".
If you want a secure login for a site, or a section of a site, you need a server-side solution (ie, ColdFusion/Lucee, PHP, JSP, etc.)
V/r,
^ _ ^
Copy link to clipboard
Copied
Many hosting plans have a C-Panel from which you can password protect a directory on the server. See link below for details.