Created
November 18, 2021 01:51
-
-
Save suragch/aa6bccae8d1bb2a4bc8716ed390ed89b to your computer and use it in GitHub Desktop.
Password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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