Forum Moderators: open
What matters more than your XHR method is that you're not using a Javascript variable to verify authentication. Security must happen at the server - with no exception. If your client-side code contains a variable like "is_admin", I can easily (I mean, really easy, trust me) change that from "false" to "true" using widely available debugging tools.
Unless you know what you're doing, authentication and AJAX are not a good mix. That said, secure authentication via AJAX *is* possible, but it's easy to do badly, so I normally don't recommend it.
Instead of XmlHttpRequest for your login form, why not just use an old-fashioned <form method=post>, and a submit button?
edited typo
but i want to know if I used GET method and received the username and password in Javascript then pass it to PHP file and check it in the database with mysql_real_escape_string and if correct then set sessions else send error.... then how can it be hacked?
Thanks again!
pass it to PHP file and check it in the database with mysql_real_escape_string and if correct then set sessions
You're using sessions instead of a client-side variable, and mysql_real_escape_string - I think you'll be OK.
If you have Web Service like http://example.com/checkpassword.php?u=&p=, make sure it's not vulnerable to a SQL injection (mysql_real_escape_string = good!), or else a hacker could use that to steal your entire db of passwords.
here is what claims to be good authentication via XHR [ajaxpatterns.org]
but i want to know if I used GET method and received the username and password in Javascript then pass it to PHP file and check it in the database with mysql_real_escape_string and if correct then set sessions else send error.... then how can it be hacked?