citeright-sdk-js
Version:
An SDK to connect to the CiteRight API.
70 lines (69 loc) • 2.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var PasswordValidationModel_1 = require("./PasswordValidationModel");
/**
* @swagger
* definitions:
* PasswordChangeDTO:
* type: object
* properties:
* oldPassword:
* type: string
* newPassword:
* type: string
* confirmPassword:
* type: string
*/
var PasswordChangeDTO = /** @class */ (function () {
function PasswordChangeDTO(oldPassword, newPassword, confirmPassword) {
if (oldPassword === void 0) { oldPassword = ""; }
if (newPassword === void 0) { newPassword = ""; }
if (confirmPassword === void 0) { confirmPassword = ""; }
this.oldPassword = oldPassword;
this.newPassword = newPassword;
this.confirmPassword = confirmPassword;
}
/**
* This function will compare two passwords to make sure they match and also validate against a list of rules
* that we insist on for password strength. Upon completion, we return a PasswordValidationModel that contains any
* errors as well as a convenient boolean to indicate validity. If an "oldPassword" is supplied, we will check to
* see if matches the new password.
*
* @returns {PasswordValidationModel}
*/
PasswordChangeDTO.prototype.validate = function () {
var response = new PasswordValidationModel_1.PasswordValidationModel();
if (!this.newPassword) {
response.errors.push("Password must not be empty");
}
else {
if (this.oldPassword && this.oldPassword === this.newPassword) {
response.errors.push("Old password can not be reused");
}
if (this.newPassword.length < 6) {
response.errors.push("Password must be at least 6 characters long");
}
if (this.newPassword !== this.confirmPassword) {
response.errors.push("Passwords do not match");
}
if (!this.newPassword.match(/\d/)) {
response.errors.push("Password must contain at least 1 number");
}
if (!this.newPassword.match(/[A-Z]/)) {
response.errors.push("Password must contain at least 1 upper case letter");
}
if (!this.newPassword.match(/[a-z]/)) {
response.errors.push("Password must contain at least 1 lower case letter");
}
if (!this.newPassword.match(/[$@!%*?&.]/)) {
response.errors.push("Password must contain at least 1 special character");
}
}
if (!response.errors.length) {
response.isValid = true;
}
return response;
};
return PasswordChangeDTO;
}());
exports.PasswordChangeDTO = PasswordChangeDTO;