View Full Version : Password script help
martynball
02-10-2008, 08:36 PM
I have got this script.
But if they get the password wrong they can still get on the page, please can someone modify it so that it redirects you to another page if you press cancel or get it wrong.
<script language="JavaScript">
<!--
var username = prompt("Enter Username In the Box Below","")
var password = prompt("Enter Password In the Box Below","")
if (username !="player08" || password !="50cal")
{ top.location="about:Bad Username and/or Password" }
//-->
</script>
CFMaBiSmAd
02-10-2008, 08:46 PM
Doing any sort of password protection in javascript code is not secure (the correct values are visible in the source code of the page in the browser.) Don't waste your time with that code. You need to use a server side solution.
martynball
02-10-2008, 08:53 PM
I know that, all they need to do is to view course. But this is only for school. and most people at my school dont know that.
martynball
02-10-2008, 09:54 PM
Help please.
Leonsbuddydave
02-10-2008, 10:05 PM
<script type="text/javascript">
<!--
function passProtect() {
var username = prompt("Enter Username In the Box Below")
var password = prompt("Enter Password In the Box Below")
if (username=="player08" && password=="50cal") {
window.location = "success.html" ;
}
else {
window.location = "failure.html";
}
}
//-->
</script>
Always use type instead of language. To change the username and password, change the corresponding ones inside the if conditions, to change the ending pages change success.html and failure.html correspondingly.
Also, prompts can get a little annoying, so if you want to use textboxes, do this:
<html>
<head>
<script type="text/javascript">
function passProtect() {
var username = document.form1.username.value;
var password = document.form1.password.value;
if (username=="player08" && password=="50cal") {
window.location = "success.html";
}
else {
window.location = "failure.html";
}
}
</script>
</head>
<body>
<form name="form1">
Username: <input type="text" name="username"><br />
Password: <input type="text" name="password"><br />
<input type="button" value="Login" onClick="passProtect()">
</form>
</body>
</html>
martynball
02-11-2008, 01:48 PM
Thanks, thats exactly what i wanted.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.