Skip to content

Instantly share code, notes, and snippets.

@suragch
Created November 18, 2021 01:51
Show Gist options
  • Save suragch/aa6bccae8d1bb2a4bc8716ed390ed89b to your computer and use it in GitHub Desktop.
Save suragch/aa6bccae8d1bb2a4bc8716ed390ed89b to your computer and use it in GitHub Desktop.
Password
class Password {
Password(String password)
: assert(password.length > 8),
_password = password;
String _password;
set value(String newPassword) {
if (_isTooShort(newPassword)) {
throw Exception('Too short!!!');
} else if (!_hasNumbersLetters(newPassword)) {
throw Exception('You must have numbers '
'AND letters!!!');
} else {
_password = newPassword;
}
}
bool _isTooShort(String password) {
return password.length <= 8;
}
bool _hasNumbersLetters(String password) {
return _hasNumbers(password) && _hasLetters(password);
}
bool _hasNumbers(String password) {
return true;
}
bool _hasLetters(String password) {
return true;
}
@override
String toString() {
final length = _password.length;
final stars = '*' * length;
return 'Password is $stars';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment