Hi everyone as my side project I wrote an Android App to generate strong password for my online accounts and I made it with Flutter. This is the Dart code that makes all happen:
import 'dart:math';
String generatePassword(bool _isWithLetters, bool _isWithUppercase,
bool _isWithNumbers, bool _isWithSpecial, double _numberCharPassword) {
String _lowerCaseLetters = "abcdefghijklmnopqrstuvwxyz";
String _upperCaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String _numbers = "0123456789";
String _special = "@#=+!£\$%&?[](){}";
String _allowedChars = "";
_allowedChars += (_isWithLetters ? _lowerCaseLetters : '');
_allowedChars += (_isWithUppercase ? _upperCaseLetters : '');
_allowedChars += (_isWithNumbers ? _numbers : '');
_allowedChars += (_isWithSpecial ? _special : '');
int i = 0;
String _result = "";
while (i < _numberCharPassword.round()) {
int randomInt = Random.secure().nextInt(_allowedChars.length);
_result += _allowedChars[randomInt];
i++;
}
return _result;
}
How to use
All you have to do is to create a dart file with the code above, name it password_generator.dart, import it in your statefull or stateless widget and directly call the generatePassword() function
import 'password_generator.dart';
String _generatedPassword = generatePassword(true, true, true, false, 17);
print(_generatedPassword);
The app is ready to download on the Play Store using this link: Wassword - Wonderful Password Generator.
Code strong, Alberto