![]() |
Password Protection Code modification
I am using a password protect code from http://javascriptkit.com/script/cut34.shtml . The code works perfect for me since i need to have different passwords to access different pages in the same interface, and here the password is the name of the html files.
Concept Used: The pop up window asks for password and then looks for an html file with the same name in the root folder. If there is no such file then the pop up stays and the base page returns again. Modification Needed: I want to make the code look for the html file in a specific folder instead of in the root. I changed the 5th line of the following code to make it location=\/folder\/password +".html"But it does not work. Kindly suggest me my mistake. needless to say that I am a beginner. Your help shall be highly appreciated. Thanks Code:
function goForit() { |
location='foldername/'+password + ".html"or location='/anotherfoldername/'+password + ".html" |
Thank You.
Thank you so much. The first one worked.
By entering the wrong password it tries to open the respective non existent html file in the folder in the directory. and stays there with a file not found page. Is there any way in using javascript, the page can be redirected to a predefined page when the user enters a password(wrong), and no such html file exists in the folder ? Please guide. |
A thought occurs that you could try to load the page in a hidden iframe, using onload to try to reference an element on the page, even document.body, and if this fails redirect to another page. But I don't know without a little googling whether onload fires if the page is not found(?).
[I think there might be another way to do this using ajax or some other similar technology.] But given that this is not secure at all.. you could store the passwords in an array and check if the one they've entered exists in the array. |
Thank you Andrew. That seems to be a clever idea. I do not have adequate know how to execute that though. I am getting the files hosted and hopefully configuring a 404 not found page might help. I will continue to investigate. Thank you again.
|
Yes I was reading a little further. If you provide your own 404 page then there will be something on the page that you can refer to that identifies it. Or, of course, this 404 page could offer to redirect the user.
I had what I thought was a clever idea, which was to wait for onload to complete and just read the location (the address); if it's different then the page they were seeking doesn't exist. But I don't know if this would work. Something like: Code:
var oIframe = document.getElementById("secretIframe"); |
Andy I would like to test this idea. Please correct me
So I need to put an i frame with id=secretIframe and then put the contents of the above code in the password seeking pop up window. What else do i need to do to achieve the redirection back to the predefined page.. where in the code does it define the predefined page. |
You could play with the following. But, erm...., it's not quite working?! Added: actually, I think it is working, if uploaded to a server.
Code:
<!DOCTYPE html> |
I tested the code in dropbox using the web address.. and it seems to be working.. but I am not able to use the code with the password pop up page i am using...
@Andy, Please see this link https://dl.dropbox.com/u/25512757/Sand-Box/index.html (note for others who are seeing this link at a later date : it has been taken off. Sorry) Currently since it is in dropbox server, it is giving a 404 page, but i want it to redirect to a predefined /dragto.html page if it is not leading the user to /Codebox/xyz.html I understand that you are saying to put your code in the popup page. bur then where should I put the secretIframe, in the resulting page (treasure) ? Please help me.. nb. I am following you in another post in an alternative to make this happen in google app engine. |
Haven't looked in detail but I'm guessing you can put the hidden iframe in the popup. If it succeeds then reload the same page in the main window, via window.opener.
I don't know what treasure refers to, unless it is a compliment :D |
:D @Andy
I am not sure.. When I put the code in the popup then it shows a messagebox in the pop up itself, as soon as it loads and on clicking ok, takes me to the dump (dragto.html)... but the user never gets to input the password... Here is the file structure I am using The desired behavior is on clicking a button in index.html it opens the gate.html as a pop up. Then if you put xyz as the password in the popup, it takes you to /Codebox/xyz.html but entering anything else should take you to dragto.html. The codes of pages without your code are the following. Code of Index.html Code:
<html>The code of gate.html Code:
<HTML> |
Code:
<!DOCTYPE html>Aaaaaarggh!! Just seen the FONT FACE and CENTER tags in your HTML.. That is a very old script :mad: |
FWIW carousel.html (not my work!!)
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
I added the above code to the pop up file and placed a carousel.html in the root drive. But I am not getting the desired result. It does not give a chance to enter the password and then takes to the dragto.html everytime... May be I am missing something here. :(
|
Did you delete the line
Code:
oIframe.src = "carousel.html"; |
| All times are GMT +1. The time now is 04:25 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.