PDA

View Full Version : Java Script Password Code



unforgettablewebdesigns
11-14-2007, 05:56 PM
I am having a problem with my code. It works fine on my computer but as soon as I upload it to the server my Login wont work.

I know using JavaScript is the furthest from secure but that's okay, I am not worried about it I just need my code fixed. Please help!!

<html>
<HEAD>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
.style13 {
color: #CC66CC;
font-weight: bold;
}
.style16 {font-size: 18px}
.style22 {font-size: 16px}
-->
</style><BODY>
<center>
<p><img src="ORIGINAL LOGO.JPG" alt="Crystal Boutique" width="300" height="100" longdesc="http://www.x.com"></p>
<p class="style10"><font size="5" face="Perpetua"> <span class="style13">Please Sign In!</span></font></p>
<p class="style10">&nbsp;</p>
</center>
<script type="text/javascript">
function submitentry(){
loggedin=false;
username="";
password="";
username=prompt ("Username:","");
username=username.toLowerCase();
password=prompt ("Password:","");
password=password.toLowerCase();

-->Enter Username/Password Below <--
if (username=="ashley00" && password=="2838") {
loggedin=true;
window.location="http://216.105.55.115/html/cbreps.html";
}
if (username=="evi01" && password=="2594") {
loggedin=true;
window.location="http://216.105.55.115/html/cbreps.html";
}
if (username=="kristen02" && password=="6510") {
loggedin=true;
window.location="http://216.105.55.115/html/cbreps.html";
}
-->Enter Username/Password Above <--

if (loggedin==false){
alert("Sorry! Invalid Login Information!")
}
}
</SCRIPT>

<center>
<form>
<input type="button" value="Sign In!" onClick="submitentry()">
</form>
</center>
<p>&nbsp;</p>
<p align="center">&nbsp;</p>
<p align="center" class="style16"><span class="style9 style22"><font face="Perpetua">If you are having problems logging in click <a href="mailto:x@comcast.net">here</a> to report it.</font> <font face="Perpetua"><br>
Click <a href="http://www.x.com">here</a> to return to main page.</font><font face="Perpetua"></font></span> </p>
</center>
</body>
</html>

boogyman
11-14-2007, 06:19 PM
Javascript cannot provide any security measures for you, so trying to capture a username / password login combination is really just a waste of storage and bandwidth.

If you have something that needs to be secured with a username / password I suggest you look into some type of server-side programming language like PHP

unforgettablewebdesigns
11-14-2007, 06:48 PM
Does that mean that there is no way possible for my code to work? And if that is true why is it working when I view it on my computer and then stops working when I upload it to the server?

I am not experienced with PHP, only JavaScript and HTML.

Can someone please help me. Like I said I am not worried about security at all! Thank you!

Trinithis
11-14-2007, 06:53 PM
Try:

window.location.href = "http://216.105.55.115/html/cbreps.html";


<input type="button" value="Sign In!" onclick="submitentry()">
(Note the lowercase onclick.)



//adding the keyword var
var loggedin = false;
var username = "";
var password = "";


Make these comments by adding // to their beginning!


//-->Enter Username/Password Below <--

and the


//-->Enter Username/Password Above <--


Lowercase your </SCRIPT>

</script>

/////////////

Not sure if these will help, but you can try.

boogyman
11-14-2007, 07:22 PM
Does that mean that there is no way possible for my code to work?
security is not the reason that it wont work, it just means that anyone can view it, they would just need to look at the source to find out the url of the redirect.


And if that is true why is it working when I view it on my computer and then stops working when I upload it to the server?
good question but on your local machine you are redirecting to another file on the same computer, you arent trying to redirect the script somewhere.



I am not experienced with PHP, only JavaScript and HTML.
thats the good thing about the web there are a vast array of tutorials on noth only javascript, html, php, but all other programming languages.




<input type="button" value="Sign In!" onclick="submitentry()">
(Note the lowercase onclick.)

that is case-insensitive, although personally I believe all lowercase is better semantics.





//adding the keyword var
var loggedin = false;
var username = "";
var password = "";


again not required, although in this case certainly much better coding technique / semantics.
Javascript is a (very very) loosely typed language pretty much accepting any case and improper technique... which is why many people have been able to take advantage of its features and turn what can be a very helpful and user-experience benefit turns into frustration and anxiety for the web and computers in general



Like I said I am not worried about security at all!

then why bother with the username / password?

I believe your problem is that the script isnt being initiated to begin with, I still strongly suggest that you use PHP or some other type of server-side programming language for securities sake, but here is a little script.



<script type="text/javascript">
function getUserAccess()
{
var user = prompt("Enter Username:", "").toLowerCase;
var pass = prompt("Enter Password:", "").toLowercase;
var okay = false;

switch(user)
{
case _user1_:
if(pass == "_pass1_") { okay = true }
break;
case _user2_:
if(pass == "_pass2_") { okay = true }
break;
case _user3_:
if(pass == "_pass3_") { okay = true }
break;
default:
okay = false;
break;
}

if(okay)
{

window.location.href="http://216.105.55.115/html/cbreps.html";
}
else
{
return alert("Incorrect Login Information");
}
}
</script>

where the text in blue corresponds to the your allowable values
that goes in your <head> tag.

then in the body declaration you would put
<body onload="getUserAccess()">


that way will provide prompts for the user to put in information, if you wished them to see the page, and use a form you could use the same function with just a few slight modifications... but I will get to that if its somethign you are interested in

Twey
11-14-2007, 08:14 PM
http://www.twey.co.uk/?q=encpass