randomPassword method
get random password randomPassword
Implementation
String randomPassword(
{bool letters = true,
bool uppercase = false,
bool numbers = false,
bool specialChar = false,
double passwordLength = 8}) {
if (letters == false &&
uppercase == false &&
specialChar == false &&
numbers == false) {
letters = true;
}
String _lowerCaseLetters = "abcdefghijklmnopqrstuvwxyz";
String _upperCaseLetters = _lowerCaseLetters.toUpperCase();
String _numbers = "0123456789";
String _special = "@#=+!£\$%&?[](){}";
String _allowedChars = "";
_allowedChars += (letters ? _lowerCaseLetters : '');
_allowedChars += (uppercase ? _upperCaseLetters : '');
_allowedChars += (numbers ? _numbers : '');
_allowedChars += (specialChar ? _special : '');
int i = 0;
String _result = "";
while (i < passwordLength.round()) {
int randomInt = Random.secure().nextInt(_allowedChars.length);
_result += _allowedChars[randomInt];
i++;
}
/// return random password
return _result;
}