...

View Full Version : External Files



homer09001
03-16-2005, 02:04 PM
Im new to JS Programming but i am getting the na gof it quickly i want to make a login script for my website which provides a prompt asking for the password which i have managed to do but what i want to do is get the script to check to see if the password entered matches a password in an external file on the same server? for security reasons!!

martijntje
03-16-2005, 02:09 PM
You cannot create a secure system with javascript only. Because javascript is a client-side language, the password information would have to be available to the browser, and therefor also available to everyone taking 30 seconds to find out how your code works.

You'd be better off using PHP for this. However, if you still wish to use an external file, you can link to your javascript file by including the following line in the head section of your page:


<script type="application/x-javascript" src="yourfile.js">

However, i say this again, is NOT SECURE!

homer09001
03-16-2005, 02:16 PM
You've confused me now, i know its not 100% secure but it better than having the passsword in the HTML itself. This is what ive written to practice with:

<script language="javascript">

myAge=* <--- this being the password which i would like the script to check from an external file

usrGuess = prompt("Guess My Age?","Type Guess here");
if (usrGuess == myAge){
window.location="http://www.google.com";
alert("Acess granted!");
}else{
window.location="http://www.aol.com";
alert("acess denied!");
}
</script>

But how can i get it so where it says if (usrGuess == myAge){ it would somehow be if (usrGuess == Name Of File and Line to read){

homer09001
03-16-2005, 02:19 PM
Or would it be possible to get the script to check the password with the acctual one in a seperate location in the web page?

martijntje
03-16-2005, 02:21 PM
As i said, you create an external file. Let's call it passwd.js to be original :P
This file should have the following contents.

var myAge='yourpasswordhere';

Then, in the head, section insert the following:

<script type="application/x-javascript" src="passwd.js">

Et voila, you now have a variable called myAge that contains your password. Easy as hell, but also easy as hell to 'crack' (it isn't even cracking, since the password is available anyways).

Also, you should use <script type="application/x-javascript> instead of <script language="whatever">

homer09001
03-16-2005, 02:24 PM
Ive got it now thank you very much i know its easy to crack but not everyone that inteligent to be able to view the source then get the file name and the rest!!

homer09001
03-16-2005, 02:26 PM
wait a minute the script still works even when the js filename is different to that in the head of the script now its not working at all

martijntje
03-16-2005, 02:31 PM
What do you mean? Post your exact page here.

homer09001
03-16-2005, 02:31 PM
Ok heres my new script:

<script type="application/x-javascript" src="010226b.js">

pWrd = prompt("Enter Password?","Type Password here");
if (pWrd == Pswrd){
window.location="http://www.google.com";
alert("Access granted!");
}else{
window.location="http://www.aol.com";
alert("Access denied!");
}
</script>

and here whst inside my js file:

var Pswrd='qweasd';

martijntje
03-16-2005, 02:34 PM
My mistake. I forgot to tell you you need to close the script tag :eek:
After the script tag in the head, there should be a </script>

homer09001
03-16-2005, 02:36 PM
still not workign now the code shows up in the html page:


<script type="application/x-javascript" src="010226b.js"></script>

pWrd = prompt("Enter Password?","Type Password here");
if (pWrd == Pswrd){
window.location="http://www.google.com";
alert("Access granted!");
}else{
window.location="http://www.aol.com";
alert("Access denied!");
}
</script>


thats wat i got

martijntje
03-16-2005, 02:41 PM
That's because you need to reopen the script tag for the validationfunction.

<script type="application/x-javascript" src="010226b.js"></script>

Then, wherever you want to call your validation function, open a new script tag. Another, probably better idea, would be to turn your validation into a function, and call it from your main document.

homer09001
03-16-2005, 02:44 PM
im confused again???? :confused: Can you pls explain with examples



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum