Use JQuery.post() with JSON for a secure login form
So I'm tring to create a secure form ( username & password ) with the usernames and passwords stored stored in a Json fil. So I have some questions.
How 开发者_运维百科can I secure that json file will not be accessible by something coming via cross-domain request? Or How can I ensure it will not.
How do I actually use the .post() the function with json. I mean I read the .post() documentation but it doesn't make much sense to me. Not how can I use it with Json at least.
The json variable is something like that: var Arr = secureData.Users;
Any suggestions on how can it be done? It shouldn't be hard from the tutorials that I read but I just don't get it.
PS: I looked into another way but that uses MySQL and PHP but I don't have a MySQL database ( nor want to build one ) and I don't use php at my site.
What exactly are you trying to achieve?
Do you want to compare the username and password entered by the user to values stored in a file on the server? Then you could use .post() to send the values submitted by the user to the server, let the server perform the comparison and return an indication of whether the authentication succeeded. In this case, although it is certainly possible, there is no particular reason to use the JSON format in the file - CSV, XML or anything like that might be just as (or more) appropriate.
EDIT: If you are not using PHP or any other server-side scripting, how do you expect to do the comparison? You obviously do not want to perform the comparison using javascript, since you will then have to send the correct values to the browser. That would obviously make your authentication mechanism very easy to circumvent / hack.
Just do not return/echo the complete JSON string with usernames/passwords in any way.
精彩评论