blob: 4a3ddbec286e0d7d941c3d01f6a11a2b22f23506 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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,
};
|