I've made an Ajax login system, which is really simple: login.php simply checks the $_POST[''] fields; if it's correct, it returns ok), by mysqli etc. I secured that part of code by my anti-SQL injection function.
Unfortunately, I don't have much experience with Javascript, and I'm concerned about the security of my approach.
Is it safe enough to put if(data=='ok') in js? Could anyone change that to (data=='') in Firebug, somehow?
$.ajax({
type: "POST",
url: "system/login.php",
data: dataString,
cache: false,
beforeSend: function(){
$("#login").val('Checking...');
},
success: function(data){
if(data=='ok'){
$("#login").val('Login')
$("#msg").html("<div class='alert alert-success' role='alert'><b>Success!</b> You have been logged successfully. </div>");
setTimeout(function(){
location.reload();
}, 2000);
}else{
setTimeout(function(){
$("#loginBox").effect( "shake" );
$("#login").val('Login');
$("#msg").html("<div class='alert alert-danger' role='alert'><b>Error!</b> Invalid username and password. </div>");}, 1000);
}
}
});