Login PHP?

Studying PHP and trying to make the entrance to the site. I don't know how to properly and safely but now the username and password are stored in a JSON file. There is such form:
<form action="/" method="post">
 <input id="login" type="text">
 <label for="login">Login</label>
 <input id="pass" type="text">
 <label for="pass">Password</label>
 <button type="submit">Login</button>
 </form>
Next, I try to handle her AJAX'om and send the entered data to the server:
document.querySelector('.login-form form').addEventListener('submit',function (el) {
el.preventDefault();
$.ajax({
 type: "POST",
 url: "./admin.php",
 data: {
 action: administration,
 login: document.querySelectorAll('.login-form form input')[0].value
 pass: document.querySelectorAll('.login-form form input')[1].value
}
});
 });

So I can understand what to do ,I need to check that the correct username and password and send the response if correct ,then go to another page ,if not ,display an error message.
if ($_POST['action'] && $_POST['action'] === 'administration'){
 if ($_POST['login'] === $data -> administration -> login && $_POST['pass'] === $data -> administration -> pass){

}
}

Strongly do not swear ,was trying to find in the Internet how to make a login using PHP ,but did not understand ,everything related to the database ,I would like to try to store data about login and password in the JSON file ,although I don't know how is correctly...
March 23rd 20 at 18:52
1 answer
March 23rd 20 at 18:54
Solution
Do this:
document.querySelector('.login-form form').addEventListener('submit',function (el) {
el.preventDefault();
$.ajax({
 type: "POST",
 url: "./admin.php",
 data: {
 action: administration,
 login: document.querySelector('.login-form form #login').value
 pass: document.querySelector('.login-form form #pass').value
},
 success: function(data) { if (data == "OK") window.location = "admin.php";}
});
 });

PHP script:
if ($_POST['action'] && $_POST['action'] === 'administration'){
 if ($_POST['login'] === $login && $_POST['pass'] === $pass){
 // here we need to do everything that needs to be done
 // .....
 // and then:
 echo("OK"); exit();
}
}
Thank you ,understood. - Eileen commented on March 23rd 20 at 18:57

Find more questions by tags JavaScriptPHPAJAX