Dart app to check password strength using simple rules: length, uppercase, lowercase, numbers, and special characters. Ready for console or Flutter.
// Password Strength Check with Simple Rules
// Constants for validation rules configuration
const int lunghezzaMinima = 8;
// Function that checks if the password is valid according to the defined rules
bool validaPassword(String password) {
// Minimum length check
if (password.length < lunghezzaMinima) {
return false;
}
// Regular expressions for various checks
final RegExp maiuscola = RegExp(r'[A-Z]');
final RegExp minuscola = RegExp(r'[a-z]');
final RegExp numero = RegExp(r'[0-9]');
final RegExp carattereSpeciale = RegExp(r'[!@#\$%\^&\*(),.?":{}|<>]');
// Check for at least one uppercase letter
if (!maiuscola.hasMatch(password)) {
return false;
}
// Check for at least one lowercase letter
if (!minuscola.hasMatch(password)) {
return false;
}
// Check for at least one number
if (!numero.hasMatch(password)) {
return false;
}
// Check for at least one special character
if (!carattereSpeciale.hasMatch(password)) {
return false;
}
// If all conditions are met, the password is valid
return true;
}
void main() {
// Password examples to test
List<String> passwordDiTest = [
'Password1!', // valid
'password1!', // missing uppercase
'PASSWORD1!', // missing lowercase
'Password!', // missing number
'Password1', // missing special character
'Pass1!', // too short
'P@ssw0rd2024' // valid
];
// Test loop and print results
for (var pwd in passwordDiTest) {
bool risultato = validaPassword(pwd);
print('Password: "$pwd" is valid? ${risultato ? 'Yes' : 'No'}');
}
}Software: Dart SDK (version 2.12 or higher for null safety support)
No external dependencies required
Main function `validaPassword` that accepts a string and returns a boolean
Configuration: validation rules defined as constants at the beginning of the code
Arduino: not applicable in this example (Dart software only)