PDA

View Full Version : Javascript Security


mck9235
01-04-2005, 11:20 PM
Okay what I am going to show you is a trick that helps add a little more security to JS. If you want a simple password protection this is for you.

<HTML>

<HEAD>



<p></p>
<form name="myform" method="post"
action="">
<p><span id="p">Enter Password [6 max]</span><br>
<INPUT name="pwd1" type="password" maxlength="6" size="20">

</form>
<input type="button" value="Validate"
onclick="validate()"/>
</p>
<script LANGUAGE = JavaScript>

function validate()
{
var entry = document.forms.myform.pwd1.value.toLowerCase();
if( entry == "yahoo") window.location = "http://www.fandango.com";
else
{
window.alert("Password Incorrect: Please retry");
document.forms.myform.pwd1.value = "";
}
}

</SCRIPT>

</HEAD>

</BODY>
</HTML>


Okay you see the password is yahoo. To add a bit more security save, and upload this file call it something like shoutbox.js etc. Make it funny, as if you named it password, anyone with a bit of knowledge could get to it.

Note: This is not extrmee security it is just better than having it all there in the source.

Next in the docuemnt you wish to have the script put this in:

<script LANGUAGE='Javascript' SRC='shoutbox.js'>

That will get the file, you could .htacess that file if you want.

shwaza
01-04-2005, 11:27 PM
Oh, that's pretty cool :) i only ever knew how to password protect with javascript by using prompts :P

Silver
01-05-2005, 12:21 PM
You could use the prompt method in the same way. This type is called an external JS file. Its easy to exploit tho, cause all u need to do is just download the file.

A suggestion is that you use a encryption mechanism with it, and test the passwd after that. By encryption, I dont mean md5 or nything, I mean ye olde simple increment of each character :P .
To make it even more difficult, you can use HTML encrypters, like this one http://www.blitzbiz123.com/Free_webmaster_...s/encryptor.zip (http://www.blitzbiz123.com/Free_webmaster_tools/downloads/encryptor.zip)

mck9235
01-05-2005, 08:32 PM
Yea, I know it is just a bit more than the plain old have-it-all-in-front-of-you script. :P