I have a question, I am starting to work with Ajax and PHP and I want to know how I can login with Ajax so that it validates the user if he is registered or not, I have my users in a MySQL database but I don't know how to do that validation.
I have a question, I am starting to work with Ajax and PHP and I want to know how I can login with Ajax so that it validates the user if he is registered or not, I have my users in a MySQL database but I don't know how to do that validation.
The database query should look something like this:
If the key has been encrypted, for example, with md5, and you don't know what database engine you are using, I recommend that you generate the key at the PHP level. Something like the following:
The SQL query can return information to you. If it returns information, it means that the user exists, otherwise, it does not. This query obviously has to be defined within a PHP method so that you can use it, and return, for example, OK if the access is correct, or FAIL if the user does not exist. There are other ways, such as indicating HTTP errors, etc, but it would complicate the exercise.
In ajax you have to indicate in which URL your validation method is located, example:
And to that URL you are going to send the username and password that the user entered, usually through the POST method. Ajax will return information, if the message is OK it means that the access is correct, otherwise, it will be a failed authentication.
I strongly recommend you review a tutorial on Youtube where all these issues are covered since there are basic concepts that you must learn so that you can continue improving in your projects.
The login process of any site is not trivial. It can be done easily with simple web access, but if you want something secure, it's not recommended to do things like...
You should be careful about sql injection and other issues
I recommend you follow this example that is based on the use of sessions. To begin with, and in terms of difficulty / safety ratio, it is very good
http://www.codingcage.com/2015/11/ajax-login-script-with-jquery-php-mysql.html