Click to See Complete Forum and Search --> : Javascript reading external file
druss
01-07-2003, 12:03 AM
I need a way to read a text document through javascript.
For example.
i have this file called password.txt
it contains my password in there, now i want a page to read that text document and use it. How can i go about that??
Thanks
Goran
khalidali63
01-07-2003, 12:19 AM
JavaScript can not read external files.You will need to resort to Server side coding to get that done.
Khalid
jalarie
01-17-2003, 09:19 AM
If you have complete control over that external file, make it a .js file and pull it in using a script/src=... line.
That is NOT a good way to keep passwords secure!
Dan Drillich
01-17-2003, 10:58 AM
“JavaScript the Definitive Guide” says –
For security reasons, client-side JavaScript does not allow the reading or writing of files. Obviously, you wouldn’t want to allow an untrusted program from any random web site to run on your computer and rearrange your files!
Cheers,
Dan
MarkR1248
01-17-2003, 05:19 PM
Druss,
Just a security question, to begin with, are you sure you want a password checker using JavaScript even if JavaScript could read external files?
I supposed you could have the password encrypted on the external javascript file, and have the JavaScript on the main page decrypt it to check against whatever the user entered.
By no means is this secure...its more like those glass enterence door, some houses have. Anyone, could just break the glass, to get inside, but having the door locked acts as a deterrent to casual snoops.
PS: My First Posting! Yay.
druss
01-17-2003, 08:16 PM
Ok so its not realy for a password, it was just a example.
what i need it for is the following:
i have a cgi script that encrypts a particular html file when its run, it then puts the encrypted source into a text document. What i need to do is have that javascript open that document, get the source then decrypt it with the function that i already have?
I do not know how to do that however.
Sorry for any misunderstanding
Thanks
Goran
MarkR1248
01-20-2003, 03:26 PM
Hi Druss,
I must say I havent dont anything like that. But, I'll take off on what jalarie has said, and add something further:
1. Have the CGI program create the text document, as a JavaScript .JS file, with its content being something like:
var 1stEncryptedLine = "AzDxGcJvnbLhQrEhTUO";
The, the JavaScript could just pull this JS file and access the contents, as varibles.
Assuming, whatever you are encrypting is small this would work. If it is, however, quiet long, then I assume you would have to write a CGI script that breaks up the content into numerous arrays and do something like:
var Line1 = "Asdfjakhgvjahghawjkle";
var Line2 = "asdflkjhavijipaowiawjrg";
and so forth...
There are security issues, of course. But, if you must absolutely do this through JavaScript, I think this is the way to go.