Click to See Complete Forum and Search --> : help with IE Prompt


huskrfreak88
02-17-2004, 07:36 PM
I am trying to password protect a page on my website with the IE Prompt. I can't figure out how to do it so that if they type the wrong password it closes, I only know how to make it close if they type the correct password. Also, the cancel button just takes you the the page, i want that to close the page as well... I'm new to JavaScript so thanks ALOT for your help! Post asap


If that doesn't make sense let me know...

Paul Jr
02-17-2004, 07:59 PM
Although most JS password scripts aren't secure and therefore shouldn't be used, this would be your solution in its simplest form

<script type="text/javascript">
var pass = prompt("Enter password", "");
if(pass !="pass") {
self.close();
}
else {
window.location.href = "http://forums.webdeveloper.com/";
}
</script>

huskrfreak88
02-17-2004, 08:14 PM
alright.... well like i said im not the brightest guy and im only 15, so its just for a personal website for some friends so securtiy isn't a big issue. Now where do i input the password in the script? thanks for speedy replies! :)

huskrfreak88
02-17-2004, 08:20 PM
hey i got that one to work! THANKS ALOT! I APPRECIATE IT... now if you would be willing to show me away for muliple passwords to work... I have a previous login page for usernames, and i would like seperate passwords for each... In my 'terms' something like " IF Password=abc or def" then open whatever... if that makes sense? AGAIN THANKS A TON!:D

Paul Jr
02-17-2004, 08:20 PM
Originally posted by huskrfreak88
Now where do i input the password in the script? thanks for speedy replies! :)
Do you mean where to you specify your password?

<script type="text/javascript">
var pass = prompt("Enter password", "");
if(pass !="thepassword") {
self.close();
}
else {
window.location.href = "http://forums.webdeveloper.com/";
}
</script>

Change the text in red to whatever you want your password to be.

Then change the text in blue to the URI of the page you want to be forwarded to if the password is correct.

Cheers ;)

huskrfreak88
02-17-2004, 08:27 PM
ok im having major problems and again thanks :) but now when i enter the correct password the password box keeps appearing... check it out if you have time...
i know geocities isn't the greatest... but i can't afford an actual domain.. so if you will help its appreciated!www.geocities.com/huskrfreak88/zmembers.html
password is derekj12

steelersfan88
02-17-2004, 08:45 PM
Multiple Passwords:

<script>

var pass = prompt("Enter password", "");
//change the number, 3, to the number of passwords you want
var passwords = new Array(3)
passwords[0] = "passwd1"
passwords[1] = "passwd2"
passwords[2] = "passwd3"
var correct = 0

for(var i=0;i<passwords.length;i++) {
if(pass == passwords[i]) {
//password correct, load page
correct++
}
}

//check if password was correct
if(correct == 0) {
//incorrect, change wrong.htm to bad passwd page
window.location = "wrong.htm"
}
</script>If this is not actually on the member's only page, add the following lines of code:

else {
//correct, change right.htm to member's page
//but only add this line if you need it (you have
//a separate login and member's page)
window.location = "right.htm"
}

huskrfreak88
02-17-2004, 08:48 PM
WOW! YOUR AWESOME!... one last thing and i am done... i promise! im really picking up on JS... is there any way to make this onLoad instead of onClick??

<BODY>

<center>
<form><input type=button value="Login!" onClick="LogIn()"></form>
</center>

(Sorry I'm not following post rules with that... Don't understand what the PHP thing is! sorry!)

steelersfan88
02-17-2004, 08:51 PM
with the method i gave you, you should simply paste at the very top of your page, not inside a function, just as I gave it to you. Therefore, the script will run and redirect if necessary before non-members from seeing the page.

(NOTE: last post was updated several times after original post with potential redirect if correct)

Therefore, just copy the lines of code, and place it at the VERY top of your page, and it should do it before loading!

huskrfreak88
02-17-2004, 08:56 PM
THANKS SOOOO MUCH! YOU GUYS ARE GREAT

huskrfreak88
02-17-2004, 09:13 PM
alright... im back! lol umm anyway to incorporate usernames into that? im guessing something like this... but how do i have it check for the relationship between username and password?? HELP! THANKS!

<script>

var user = prompt("Enter Username", "");
var usernames = new Array(5)
username[0] = "lindsay"
username[1] = "amanda"
username[2] = "derek"
username[3] = "kim"
username[4] = "katie"

var pass = prompt("Enter password", "");
var passwords = new Array(5)
passwords[0] = "lindsay"
passwords[1] = "amanda"
passwords[2] = "derek"
passwords[3] = "kim"
passwords[4] = "katie"
var correct = 0

for(var i=0;i<passwords.length;i++) {
if(pass == passwords[i]) {
//password correct, load page
correct++
}
}

//check if password was correct
if(correct == 0) {
window.location = "Alert.html"
}
else {
window.location = "zmembers.html"
}

</script>

huskrfreak88
02-17-2004, 10:01 PM
i know im getting old, but Steelersfan or anyone else i found what i would liek, but i want it on load, without the button... please help if possible!
Password Prompt... I would like without the button click! (http://javascript.internet.com/passwords/multiple-users-prompt-source.html)

tahuya_rat
02-18-2004, 06:50 AM
Try this on for size:



<script>

var user = prompt("Enter Username", "");
var usernames = new Array(5)
username[0] = "lindsay"
username[1] = "amanda"
username[2] = "derek"
username[3] = "kim"
username[4] = "katie"

var iCorrectUser;
for (var i=0; i<username.length; i++)
{
if (username[i])
{
iCorrectUser = i;
break;
}
}
if (!iCorrectUser)
{
window.location = "alert.html";
}
var pass = prompt("Enter password", "");
var passwords = new Array(5)
passwords[0] = "lindsay"
passwords[1] = "amanda"
passwords[2] = "derek"
passwords[3] = "kim"
passwords[4] = "katie"
var correct = 0


//check if password was correct
if(pass != passwords[iCorrectUser]) {
window.location = "Alert.html"
}
else {
window.location = "zmembers.html"
}

</script>



HTH

-tahuya_rat

steelersfan88
02-18-2004, 01:52 PM
Or:

<script>

var user = prompt("Enter Username", "");
var usernames = new Array(5)
username[0] = "user1"
username[1] = "user2"
username[2] = "user3"
username[3] = "user4"
username[4] = "user5"

var pass = prompt("Enter password", "");
var passwords = new Array(5)
passwords[0] = "password1"
passwords[1] = "password2"
passwords[2] = "password3"
passwords[3] = "password4"
passwords[4] = "password5"
var correct = 0

for(var i=0;i<passwords.length;i++) {
if(pass == passwords[i] && user = username[i]) {
//password correct, load page
correct++
}
}

//check if password was correct
if(correct == 0) {
window.location = "wrong.html"
}
// if not on member's page, add the following lines of code,
//otherwise delete the else { ... { lines
else {
window.location = "members.html"
}

</script>

BrainDonor
02-18-2004, 03:01 PM
In steelersfans88's reply, add an "s" to the array username...

usernames[0] = "user1"

Also, add another "=" and an "s" to the following line...

for(var i=0;i<passwords.length;i++) {
if(pass == passwords[i] && user = username[i]) {
//password correct, load page
correct++
}
}


Should be...

for(var i=0;i<passwords.length;i++) {
if(pass == passwords[i] && user == usernames[i]) {
//password correct, load page
correct++
}
}

Tom

huskrfreak88
02-18-2004, 03:36 PM
ok... umm in the first post with username script there is no password required just type user name and it lets you in... and on the second no prompt box appears.... help.? maybe its ME!

BrainDonor
02-18-2004, 04:37 PM
I got it working okay after applying the changes I mentioned above. I had the same problems initially. Try this.

<html>
<head>

<script language="javascript">
var user = prompt("Enter Username", "");
var usernames = new Array(5)
usernames[0] = "user1"
usernames[1] = "user2"
usernames[2] = "user3"
usernames[3] = "user4"
usernames[4] = "user5"

var pass = prompt("Enter password", "");
var passwords = new Array(5)
passwords[0] = "password1"
passwords[1] = "password2"
passwords[2] = "password3"
passwords[3] = "password4"
passwords[4] = "password5"
var correct = 0

for(var i=0;i<passwords.length;i++) {
if(pass == passwords[i] && user == usernames[i]) {
correct++
}
}

//check if password was correct
if(correct == 0) {
window.location.href = "leave_page.html"
}else{
window.location.href = "members.html"
}

</script>
</head>
<body>
</body>
</html>

huskrfreak88
02-18-2004, 04:45 PM
HAHA! AWESOME!!! i don't know how you guys (or girls) know all this! but its amazing! and i thank you for it!! I will recommend you to friends! :)

steelersfan88
02-18-2004, 05:06 PM
yea sorry bout that, kinda rushed it a tad!

BrainDonor
02-18-2004, 05:08 PM
No biggie...I am truly a newb at all this too...but because of this site and everyone here, I have learned loads!

:)

BAOTINGdG
03-12-2006, 12:13 AM
Erm hi hello!! im having problems with setting a passwordprompt for my blog... it's kinda frustrating. i was searching for ways n i stumbled upon tis site, but th htmls doesn't workk! th prompt keep appearing.. moreover im directed t my blog when i click cancel! can anyone pls teach me something on tis?