PDA

View Full Version : password redirect


littlehank
04-30-2006, 06:47 PM
I am new to javascript, and I am trying to make a password page that redirects you if the password is correct. This is what I have in the password page, called login.html:
<head>
<script src="pwrd.js"></script>
<script language=javascript>
function login(x) {
if(x==pwrd) {
window.location = redir;
} else {
window.location = "wrongpass.html";
}
}
</script>
</head><body bgcolor=000000>
<form method=post onsubmit=login(pass)>
<font face="Courier New" size=3 color=#00ff00>Password: <input type="password" name="pass">
<input type=submit value="Submit">
</form>
</body>
and I have this in pwrd.js:
var pwrd=lala;
if(new_loc==forum) {
var redir=mboard/index.html;
}
The link to login.html looks like this: <a href="login.html?new_loc=forum">
I cannot figure out what I am doing wrong. It's probably something really simple. Please point out what the problem is.

Vege
04-30-2006, 07:28 PM
javascripts and passwords dont work together

for reference, consider following fully functional serverside example:

admin.php (includes the form)
<?php
session_start();

if (($_POST['name'] == "admin") && ($_POST['pass'] == "123456"))
{

$_SESSION['loggedin']="1";
header("Location: edit.php");
}
?>
<html>
<head>
</head>
<body>
<form action="admin.php" method="post">
username:<br>
<input type="text" name="name" size="10"><br>
password:<br>
<input type="password" name="pass" size="10"><p>
<input type="submit" value="login">
</form>

</body>
</html>

edit.php (which is protected)
<?php
session_start();
if ($_SESSION['loggedin']=="1")
{
echo "<h1>your now logged in</h1>";
}
else
{
echo "you have no business here";
}
?>

Tham
05-01-2006, 12:27 PM
I don't even know why people still put Password Protection in Javascript turorials :disagree: . The problem is that your passwords will be stored in the HTML file. All someone needs do is look at the source of the HTML file and they have access.

Vege is right. To be effective you want to use a Server Side Script like Php (His example) or Perl (my example). Go to www.tommyhamilton.com/atoz/login to see the demo. There you can login, add users, upload files etc etc etc. But just stay away from the Javascript for this. :disagree: