The main thing to keep in mind is that when using AJAX, you essentially provide an interface to your database. For example, if you check for duplicate usernames (which you CANNOT do in javascript) or duplicate emails to provide a message such as "this username is already in use ... try another", you provide an interface for a potential hacker to check immediately, what usernames and / or emails are available. Security issues are not the same as for javascript. My advice to you on this topic is: (1) Use parameterized queries to access the database, as already mentioned. (2) Implement a delay on the ajax.php page - the length depends on the scenario - I go for about 1 second (3) Perform ajax when blurring or losing focus, and not on every click, (4) Implement a check in your ajax handler that guarantees that the request comes from the expected page (i.e. not some random script hacker wrote). (5) ONLY make an AJAX call when some other basic form element check has occurred [i.e. Basic JavaScript Validation]
Hope this helps. Validating a form with ajax is absolutely no different from the fact that it even remotely resembles javascript validation. This is the interface in your database, and you need to be careful with it.
This helps to imagine how you could hack your own site — knowing which email addresses are registered on your site — is a great place to start. So I could write a script to generate random email addresses using common words and / or names and hack an ajax handler to get a list of registered email addresses on your site. I could do it quickly if you did not follow the advice (1) - (5) that I mentioned above. As soon as I get letters, I will just kill them ... most likely, it gives me a name. I can guess the username from there. So now I have a username and email address. Passwords will take too long to explain, but if I can easily get usernames or emails ... it marks you as a target and you get more attention that you really need.
I am currently working on a registration verification system. Go share it with you with pleasure, if you want. I guess I'm missing something important!
World.
Chris b
source share