PDA

View Full Version : Security help



Jas
01-05-2007, 11:55 PM
Before I start, let me say that I know JS stinks as a security system for websites because it can be hacked into, but I am experimenting with it, as sort of a way to see what JS can do.

My idea is that users have a security card (such as a USB Drive with the JS file on it) that they plug in to unlock pages in the site. This process has proved to be complicated though--I have run into several problems.

First (simple problem but I didn't see it on the forum), how do you search an array? (i.e. var code= new array("01", "02", "03"), how do you search it for, say, a var named accessString?)

Second, how can I write to a external js file, and not only that but define where I want to write in that JS file? (i.e. write "01234" on lane 18, character 23 of keystart.js) Is that even possible?

Thanks!

Twey
01-06-2007, 12:32 AM
First (simple problem but I didn't see it on the forum), how do you search an array? (i.e. var code= new array("01", "02", "03"), how do you search it for, say, a var named accessString?)There is a method of Array called indexOf, which works similarly to that of a string. However, it's not implemented in JScript, so it's necessary to implement it in script:
if(typeof Array.prototype.indexOf !== "function")
Array.prototype.indexOf = function(needle) {
for(var i = 0; i < this.length; ++i)
if(this[i] == needle)
return i;
return -1;
}
Second, how can I write to a external js file, and not only that but define where I want to write in that JS file? (i.e. write "01234" on lane 18, character 23 of keystart.js) Is that even possible?Not reliably. It's possible using ActiveX or Java, but rather pointless when it's so much simpler to do it server-side.

Jas
01-06-2007, 01:48 AM
Thanks Twey
I'll have to check out the indexOf.

So suppose that I don't care about reliability =P
How could I get the writing in external JS file to work?

djr33
01-06-2007, 06:15 AM
You could just create the file instead... might be a BIT easier.

Not really sure about java/activex myself. Seems complex to me too.

Twey
01-06-2007, 01:56 PM
You'd need to create and sign a Java applet, or use an ActiveX object as explained in this article (http://www.c-point.com/JavaScript/articles/file_access_with_JavaScript.htm). Since you're only experimenting, the latter option is probably simpler, but of course it only works on IE.

Jas
01-06-2007, 05:18 PM
Thanks again, but I think I'm more lost now. . . I guess I'll have to study. . .

Jas
01-06-2007, 10:13 PM
One more thing, how do I get the indexOf thing to work? I can't figure it out. . . Newbie. . .
(The var = accessString, the string = code)
Or if you know a good tutorial