I currently have a standard login form like this:
<?php
if( isset( $_POST['username], $_POST['password'] ) ) {
// escape both strings and compare them to database
}
?>
<form action="" method="post">
<input type='text' value='username' name='username'></input>
<input type='password' value='password' name='password'></input>
<input type='submit' value='submit'></input>
</form>
I want to move to AJAX, so the new page doesn't refresh. This is my new method:
<script>
function login_ajax() {
var formdata = new FormData();
var ajax = new XMLHttpRequest();
formdata.append('username', document.getElementById('username').value;
formdata.append('password', document.getElementById('password').value;
ajax.open( "POST", "https://my-website.com/login_validation.php" );
ajax.onreadystatechange = function() {
if(ajax.readyState == 4 && ajax.status == 200) {
// do something
}
}
ajax.send( formdata );
}
</script>
?>
<form action="" method="post" onsubmit='login_ajax(); return false;'>
<input type='text' value='username' id='username'></input>
<input type='password' value='password' id='password'></input>
<input type='submit' value='submit'></input>
</form>
And my login_validation.php
looks like this:
<?php
if( isset ( $_POST['username'], $_POST['password'] ) ) {
// escape strings compare to database and sign on
}
Is the second method less secure than the first?