-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathValidator.js
More file actions
21 lines (17 loc) · 813 Bytes
/
Validator.js
File metadata and controls
21 lines (17 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import resourcesInstance from "./Resources.js"
export class Validator {
static #PASSWORD_REGEX_DIGITS = /\d/g
static #PASSWORD_REGEX_LOWERS = /[a-z]/g
static #PASSWORD_REGEX_CAPITALS = /[A-Z]/g
static validatePassword(password) {
return [
password.length >= resourcesInstance.minLength(),
this.#checkPasswordParameter(password, resourcesInstance.minDigits(), this.#PASSWORD_REGEX_DIGITS),
this.#checkPasswordParameter(password, resourcesInstance.minLowers(), this.#PASSWORD_REGEX_LOWERS),
this.#checkPasswordParameter(password, resourcesInstance.minCapitals(), this.#PASSWORD_REGEX_CAPITALS)
].every(validation => validation === true)
}
static #checkPasswordParameter(text, occurrences, pattern) {
return text.length > 0 ? (text.match(pattern) ?? []).length >= occurrences : false
}
}