...

View Full Version : HTML LOGIN HELP!!!! Urgent pls help me :)



Fusioner
01-16-2012, 03:19 AM
i am having a simple login system, but i need some help i want to assign an if else statement my code is this :
what i need is if i login to sales if navigates to sales page,
if other then go to other page pls help me It is very important for me
Thanks is advance



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ENTER USER NAME&nbsp; ENTER PASSWORD</title>
<style type="text/css">
.style1 {
text-align: center;
}
</style>
</head>

<body style="background-color: #AFC8C7">
<script type = "text/javascript">

// Note: Like all Javascript password scripts, this is hopelessly insecure as the user can see
//the valid usernames/passwords and the redirect url simply with View Source.
// And the user can obtain another three tries simply by refreshing the page.
//So do not use for anything serious!

var count = 2;
function validate() {
var un = document.myform.username.value;
var pw = document.myform.pword.value;
var valid = false;

var unArray = ["HR", "Admin", "IT", "Sales"]; // as many as you like - no comma after final entry
var pwArray = ["hr123", "admin123", "it123", "sales123"]; // the corresponding passwords;

for (var i=0; i <unArray.length; i++) {
if ((un == unArray[i]) && (pw == pwArray[i])) {
valid = true;
break;
}
}

if (valid) {
alert ("Login was successful");
window.location = "index.html";
return false;
}

var t = " tries";
if (count == 1) {t = " try"}

if (count >= 1) {
alert ("Invalid username and/or password. You have " + count + t + " left.");
document.myform.username.value = "";
document.myform.pword.value = "";
setTimeout("document.myform.username.focus()", 25);
setTimeout("document.myform.username.select()", 25);
count --;
}

else {
alert ("Still incorrect! You have no more tries left!");
document.myform.username.value = "No more tries allowed!";
document.myform.pword.value = "";
document.myform.username.disabled = true;
document.myform.pword.disabled = true;
return false;
}

}

</script>

<form name = "myform">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p class="style1">User Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="username" style="width: 131px">
</p>
<p class="style1">&nbsp;Password:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;
<input type="password" name="pword" style="width: 131px">&nbsp;
</p>
<p class="style1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" value="Log In" name="Submit" onclick= "validate()" style="width: 96px">
</p>

</form>
<div style="position: absolute; width: 100px; height: 100px; z-index: 1; left: 136px; top: 252px" id="layer1">
</div>
<p>&nbsp;</p>
</body>

</html>

VIPStephan
01-16-2012, 01:46 PM
In future, please wrap any code you post in between
tags (e. g. by using the small ‘#’ button above the reply field). That makes it much easier to read your post and much more likely for anyone to respond.
Read the posting guidelines (http://www.codingforums.com/postguide.htm) (especially point 2) regarding words like “urgent” in the thread title. As Benjamin Franklin said: “He that can have patience can have what he will.”
Your problem is not an HTML problem because HTML doesn’t have if/else statements and can’t redirect based on a certain user interaction. Since I don’t see any server side code in there (altough that’s what should be used for what you want) I assume you’re actually having a JavaScript question. I’m moving your post accordingly (although I still suggest you use a server side script!).

Philip M
01-16-2012, 03:09 PM
Are you not able to make this simple alteration yourself?


if (valid) {
alert ("Login was successful");
if (un == "Sales") {
window.location.href = "salesPage.html";
}
else {
window.location.href = "otherPage.html";
}
return false;
}

The code includes a couple of typos - & nbsp instaeasd of &nbsp.

ONCE MORE:-

Note: Like all Javascript password scripts, this is hopelessly insecure as the user can see the valid usernames/passwords and the redirect url simply with View Source. And the user can obtain another three tries simply by refreshing the page. So do not use for anything serious!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum