• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Simple Password Protection on DW page

New Here ,
Dec 17, 2009 Dec 17, 2009

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 &lt; 3) { if (!pass1) history.go(-1); if (pass1.toLowerCase() == \\&quot;community\\&quot;) { 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()!=\\&quot;password\\&quot; & testV ==3) history.go(-1); return \\&quot; \\&quot;; }

Thanks in advance for your help!  Brent

Views

25.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jun 21, 2018 Jun 21, 2018

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,

^ _ ^

Votes

Translate

Translate
Explorer ,
Oct 31, 2014 Oct 31, 2014

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

Password Protect a Single File With HTAccess

http://www.htaccesstools.com/articles/password-protection/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 31, 2014 Oct 31, 2014

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 31, 2014 Oct 31, 2014

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 31, 2014 Oct 31, 2014

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.

mod_auth_form - Apache HTTP Server Version 2.4

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 21, 2018 Jun 21, 2018

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 21, 2018 Jun 21, 2018

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,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 21, 2018 Jun 21, 2018

Copy link to clipboard

Copied

LATEST

Many hosting plans have a C-Panel from which you can password protect a directory on the server.   See link below for details.

https://www.inmotionhosting.com/support/website/protecting-files/how-do-i-password-protect-a-directo...

Nancy O'Shea— Product User, Community Expert & Moderator

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines