0

My login form works fine unless the user passes strings like '1 or 1' or '1'='1' which ignores the login process and validate the user anyway.

Here is my client side code.

$scope.user_login=function(){
    if($scope.user_name==''){
        alert('user name filed should not keep blank');
        loginField.borderColor('txtname');
    }else if($scope.user_pass==''){
        alert('password filed should not keep blank');
        loginField.borderColor('txtpwd');
    }else{
        var userData={'user_name':$scope.user_name,'user_pass':$scope.user_pass};
        $http({
            method: 'POST',
            url: "php/Login/login.php",
            data: userData,
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).then(function successCallback(response){
            console.log('login',response);
            //alert("aa"+response.data['msg']);
            if(response.data['user_type']=='1'){
            $location.path('dashboard');
            }

        },function errorCallback(response) {
            //alert(""+response.data['msg'].length);
            if(response.data['msg'].length > 0)
                alert(response.data['msg']);
            $scope.user_name=null;
            $scope.user_pass=null;
        });

    }
    }

Please help me to resolve this issue.

Charlie
  • 22,886
  • 11
  • 59
  • 90

1 Answers1

0

This is sql injection. It should be prevented in your login.php.

Please read this article and use the techniques described in it to solve your problem.

Here is an SO question about this: How can I prevent SQL injection in PHP?

Community
  • 1
  • 1
Charlie
  • 22,886
  • 11
  • 59
  • 90