diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
| commit | c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch) | |
| tree | 3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/js/accountConstraints/account.js | |
add: graphs et rushs
Diffstat (limited to 'graphs/js/accountConstraints/account.js')
| -rw-r--r-- | graphs/js/accountConstraints/account.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/graphs/js/accountConstraints/account.js b/graphs/js/accountConstraints/account.js new file mode 100644 index 0000000..4a3ddbe --- /dev/null +++ b/graphs/js/accountConstraints/account.js @@ -0,0 +1,42 @@ +"use strict"; + +const { + InvalidUsernameError, + InvalidPasswordError, + InvalidYearOfBirthError, +} = require("./accountError"); + +class Account { + // FIXME DONE: A constructor was deleted here + constructor(username, password, yearOfBirth) { + const regUsername = /^[a-zA-Z0-9\-_]+$/; + const lower = /[a-z]/; + const upper = /[A-Z]/; + const digits = /[0-9]/; + + if (!regUsername.test(username)) { + throw new InvalidUsernameError("Invalid username."); + } + + this.username = username; + if ( + !password.match(lower) || + !password.match(upper) || + !password.match(digits) || + password.length < 8 || + password.length > 100 + ) { + throw new InvalidPasswordError("Invalid password."); + } + + this.password = password; + if (yearOfBirth <= 1800 || yearOfBirth > new Date().getFullYear()) { + throw new InvalidYearOfBirthError("Invalid birth year"); + } + + this.yearOfBirth = yearOfBirth; + } +} +module.exports = { + Account, +}; |
