3

I have a server-side JSON array which I can retrieve. However I have issues trying to use the objects of the array as login details.

$scope.loginvalidator = function(){
   var logins = [ 
        { 
        username: $scope.Users.LoginName,
        password: $scope.Users.Password,
        },
         { 
           username: '1',
           password: '1',
         },
          ];
 for(var i = 0; i<logins.length; i++) {
    if ($scope.userInput == logins[i].username &&
        $scope.pswInput == logins[i].password){
          $scope.feedback = 'Login Successful';
          return true;
    }
    else {$scope.feedback = 'Login Failed';}
  }
  };

My code is only recognizing the hardcoded words and not reading $scope.Users.LoginName/Password as the LoginName and Password kept in the JSON array. I have bound the file read to an ng-click which I run before trying to login.

1
  • Are you sending all your usernames and passwords to the browser? That's not remotely secure. Commented May 15, 2019 at 8:19

1 Answer 1

1

It looks like the for loop is not stopped. Instead of 'return true', try 'break;'

for(var i = 0; i<logins.length; i++) {
  if ($scope.userInput == logins[i].username &&
    $scope.pswInput == logins[i].password){
      $scope.feedback = 'Login Successful';
      break; //change this line
    }
    else {$scope.feedback = 'Login Failed';}
  }
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.