View Full Version : locking pages?
fallenpacker321
07-08-2003, 12:52 PM
can someone tell me how to password protect a link and or page using html code, or just in frontpage.
ronaldb66
07-08-2003, 01:24 PM
You'll need some sort of scripting for that, and to give it any sense of security that would be server side.
.htaccess if you are on Apache. Google for '.htaccess' and 'password' and you'll find all about it. :)
Ben@WEBProp
07-08-2003, 05:21 PM
Here is a faily good passwording system that I use on a couple of pages. You can't copy it directly into frontpage ( i'm using it too :cool: ), so you will have to type it in manually...but be sure to copy it exactly!!!!! You will want to type this in after the <head> tag, but before the </head> tag...get it? Here is the code:
<script language="javascript" type="text/javascript">
function ask()
{
pass=prompt("This page is password protected. Please enter your password in the box below.","");
if(pass=="beta" && pass!=null)
{
alert("Correct password. Access granted");
}
else
{
alert("Your access has been denied because you have supplied an incorrect password. You will now be taken back to our home page.")
window.location="../first.htm"; }
}
window.onload=ask
//stop-->
</script>
You don't really need to change anything. There are only a few things that you SHOULD change:
1)if(pass=="beta" && pass!=null) ---You can change the word beta to whatever you want the password to be (leave the quotation marks). Beware though, the password is case sensistive!
2)window.location="../first.htm" ----Change ../first.htm to your homepage name. The ../ means "up one level from the file where the page is". You know, if the page you are protecting by putting this code into is in C:/myweb/folder1/page.htm but youre homepage is just in C:/myweb/page.htm then you need to have one ../ However if the homepage is two levels up, then use../../index.htm and so on and so forth.
Now to the things that you CAN change, but you don't have to:
1)pass=prompt("This page is password protected. Please enter your password in the box below." --- This is the initial message to the user trying to gain access to youre page. Feel free to change the message in quotations to fit what you want to say.
2)alert("Correct password. Access granted"); ----This is the message that greets a user with the correct password. Feel free to change that which is in quotations...
3)alert("Your access has been denied because you have supplied an incorrect password. You will now be taken back to our home page.") -----This is the message that a user who supplies the wrong password will get. Again, change the words in the quotations if you feel like you want to.
It's that easy!! Although it wont protect against everyone, it is still pretty good.
-Ben
ReadMe.txt
07-08-2003, 07:36 PM
Sorry to have to correct you there Ben, but that script will not protect agains't anyone who wants to sidestep it. The easiest way of password protecting a page is like so:
<script>
function password() {
pass = prompt("This page is password protected. Please enter your password in the box below.","");
location.href = pass+".htm";
}
</script>
<button onclick="password()">Enter Password</button>
then you simply name your page something unusual such as hahayouwontguessthis.htm then the password becomes hahayouwontguessthis. simple enough and basically foolproof.
Ben@WEBProp
07-08-2003, 09:28 PM
I know that you can turn off the Javascript and sidestep it like that, but how else do you do it? Your script has that same problem...in fact all scripts have that same problem...
Nightfire
07-08-2003, 09:59 PM
I think redme means his would be more 'secure' as his script doesn't contain the password, where as yours is easy to find the password ;)
Ben@WEBProp
07-08-2003, 10:03 PM
Oh ya...I'm aware of that "error as well. But doesnt the user need to get the password right in order to view the source code? Or is there a way to remotely access a source code?
Ben@WEBProp
07-08-2003, 10:04 PM
Oh ya...I'm aware of that "error as well. But doesnt the user need to get the password right in order to view the source code? Or is there a way to remotely access a source code?
Ben@WEBProp
07-08-2003, 10:04 PM
Oh ya...I'm aware of that "error as well. But doesnt the user need to get the password right in order to view the source code? Or is there a way to remotely access a source code?
Roy Sinclair
07-08-2003, 10:13 PM
Looks like you leaned on the "Post" button there Ben.
Right-click on the web page and "View Source" is one of the options, no password or anything else required.
If you move it into a separate .JS file the person only has to put the url for the .JS file into the address line of the browser to get an instant listing.
That's not even considering the nice macro you can find in the Post A Javascript forum here which'll create a nicely formatted page showing the page source.
SDP2006
07-08-2003, 11:30 PM
If you really want it to be secure, you'll need to do something by the way of server side. I recommend .htaccess
fallenpacker321
07-12-2003, 11:28 PM
thanks for all the info guys ill be sure to try it
cg9com
07-12-2003, 11:40 PM
Originally posted by Ben@WEBProp
is there a way to remotely access a source code?
IE:
view-source:website
Also you could check out: http://www.codingforums.com/showthread.php?s=&threadid=10114
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.