0

I'm trying to run an isolate to run my offline hashing auth function. I'm condensing all the data into one list, then I'm assigning it in the function.

For some strange reason the 2nd loop runs and the other 2 don't. The first two were created to solve the third not running, now the first doesn't run either. What am I missing here? I've never seen a loop not run without errors thrown.

Future<bool> offlineAuthenticationThread(List<Tuple2<String, String>> storedCredentials) async {
  print('Isolate running');
  final DBCrypt hashing = DBCrypt();
  bool authorized = false;
  String userName = storedCredentials[0].item1;
  String password = storedCredentials[0].item2;
  List<String> usernameHashes = [];
  List<String> passwordHashes = [];
  storedCredentials.removeAt(0);

  for (var index = 0; index >= storedCredentials.length; index++) {
    print('1');
    usernameHashes.add(storedCredentials[index].item1);
    passwordHashes.add(storedCredentials[index].item2);
  }

  for (var index = 0; index >= usernameHashes.length; index++) {
    print('2');
    (hashing.checkpw(userName, usernameHashes[index]) && hashing.checkpw(password, passwordHashes[index]))
        ? authorized = true
        : authorized = false;
  }

  for (var index = 1; index >= storedCredentials.length; index++) {
    print('3');
    (hashing.checkpw(userName, storedCredentials[index].item1) &&
            hashing.checkpw(password, storedCredentials[index].item2))
        ? authorized = true
        : authorized = false;
  }
  return authorized;
}
RobbB
  • 1,214
  • 11
  • 39
  • You set `index` to 0 and then use `>=` in your conditional. The result is that your loop will only start if `storedCredentials.length` is 0. Since you increment `index` every iteration, your loop would also run infinitely. I think you mean to use `<`, not `>=`. – PatrickMahomes Jul 27 '21 at 07:40
  • Wow, dumb mistake. Actually not enough study on loops and operators. Thanks for the help :) – RobbB Jul 27 '21 at 17:15

0 Answers0