Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13

Thread: External Files

  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question External Files

    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!!

  • #2
    New Coder
    Join Date
    Mar 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    <script type="application/x-javascript" src="yourfile.js">
    However, i say this again, is NOT SECURE!

  • #3
    New Coder
    Join Date
    Mar 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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){

  • #4
    New Coder
    Join Date
    Mar 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #5
    New Coder
    Join Date
    Mar 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Code:
    var myAge='yourpasswordhere';
    Then, in the head, section insert the following:
    Code:
    <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">

  • #6
    New Coder
    Join Date
    Mar 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!!

  • #7
    New Coder
    Join Date
    Mar 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #8
    New Coder
    Join Date
    Mar 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What do you mean? Post your exact page here.

  • #9
    New Coder
    Join Date
    Mar 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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';

  • #10
    New Coder
    Join Date
    Mar 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My mistake. I forgot to tell you you need to close the script tag
    After the script tag in the head, there should be a </script>

  • #11
    New Coder
    Join Date
    Mar 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #12
    New Coder
    Join Date
    Mar 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #13
    New Coder
    Join Date
    Mar 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    im confused again???? Can you pls explain with examples
    Last edited by homer09001; 03-16-2005 at 02:51 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •