Home > Software design >  multi user login system in angular js without database
multi user login system in angular js without database

Time:12-14

single user login:

$scope.submit = function(){

  if($scope.uname == "fida" && $scope.password == "fida"){
    console.log("correct");
    $location.path('/homePage');
  }
  else{
    console.log("wrong");
    $location.path('/loginPage');
    alert("wrong username and password");
  }
};

need to login multiple users without using the database. can anyone please help me..?can I do with array..? I am new to programming.

CodePudding user response:

You can use the array methods some or find to check a pre populated array if the credentials are correct!

$scope.users = [
{uname: 'test', password: 'test'},
{uname: 'test1', password: 'test1'},
{uname: 'test2', password: 'test2'},
{uname: 'test3', password: 'test3'},
{uname: 'test4', password: 'test4'},
{uname: 'test5', password: 'test5'},
]

$scope.submit = function(){

  // if($scope.uname == "fida" && $scope.password == "fida"){

  if($scope.users.some(x => x.uname === $scope.uname && x.password === $scope.password)){
    console.log("correct");
    $location.path('/homePage');
  }
  else{
    console.log("wrong");
    $location.path('/loginPage');
    alert("wrong username and password");
  }
};
  • Related