validatePassword
Description
Resolves the password string if it validates against the criteria. The criteria is to have at least one lowercase, uppercase, number, and symbol !@#$%&? and be 12+ character long. Also, no more than 3 consecutive repeated characters are allowed: eg: 'aaaaaa' or '55555'.
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<string || Array> | |
Related Functions | Function Signature | |
function validatePassword(password[, tuple]): Promise<string || Array> |
Examples
1
2
3
import { validatePassword } from "puddy-m/lib/validators/com";
validatePassword("pass1234!Pass1234!").then(console.log); // prints 'pass1234!Pass1234!'
1
2
3
4
5
6
import { validatePassword } from "puddy-m/lib/validators/com";
import { validateString } from "puddy-m/lib/validators"
validatePassword("pass1234!Pass1234!", [])
.then((tuple) => validateString("valid pass", tuple))
.then(console.log); // prints ['pass1234!Pass1234!', 'valid pass']
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { validatePassword } from "puddy-m/lib/validators/com";
const run = async () => {
try {
const pass = await validatePassword("pass1234!Pass1234!");
console.log(pass); // Prints "pass1234!Pass1234!"
} catch (e) {
console.log(e);
}
};
run();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { validatePassword } from "puddy-m/lib/validators/com";
const run = async () => {
try {
const pass = await validatePassword("pass1234!");
console.log(pass); // Because pass doesn't meet the criteria, it will throw
} catch (e) {
// Throws PasswordValidationError
console.log(e);
}
};
run();