Skip to content

Instantly share code, notes, and snippets.

@omarzer0
Created October 27, 2022 16:42
Show Gist options
  • Save omarzer0/3c46dca2db53c5a06aad0706c4f115f6 to your computer and use it in GitHub Desktop.
Save omarzer0/3c46dca2db53c5a06aad0706c4f115f6 to your computer and use it in GitHub Desktop.
Measure passwords strength task of flutter sessions at Roqay
import 'dart:convert';
import 'dart:io';
void main() {
var pass = stdin.readLineSync(encoding: utf8) ?? "";
getPasswordStrength(pass);
}
void getPasswordStrength(String pass) {
/// My Solution (session solution uses multiple vars instead of list)
List<String> chars = pass.trim().split("");
int numberIndex = 0, specialIndex = 1, upperIndex = 2, lowerIndex = 3;
List<int> checks = [0, 0, 0, 0];
chars.forEach((c) {
if (int.tryParse(c) != null) {
checks[numberIndex] = 1; // has numberIndex
} else {
if (c == c.toLowerCase() && c == c.toUpperCase()) {
checks[specialIndex] = 1; // has specialIndex
} else if (c == c.toUpperCase()) {
checks[upperIndex] = 1; // has upperIndex
} else if (c == c.toLowerCase()) {
checks[lowerIndex] = 1; // has lowerIndex
}
}
});
int result = 0;
checks.forEach((element) {
result += element;
});
switch (result) {
case 0:
print("Invalid!");
break;
case 1:
print("Very Weak!");
break;
case 2:
print("Weak!");
break;
case 3:
print("Medium!");
break;
case 4:
print("Strong!");
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment