Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added validations for passwords #2313

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/apim.runtime.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { RoleBasedSecurityRuntimeModule } from "@paperbits/core/security/roleBas
import { staticDataEnvironment } from "./../environmentConstants";
import { AccessTokenRefrsher } from "./authentication/accessTokenRefresher";
import "./bindingHandlers/acceptChange";
import "./bindingHandlers/passwordValidator";
import "./bindingHandlers/barChart";
import "./bindingHandlers/copyToClipboard";
import "./bindingHandlers/fastForeach";
Expand Down
25 changes: 25 additions & 0 deletions src/bindingHandlers/passwordValidator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as ko from "knockout";
import { ValidationMessages } from "../components/users/validationMessages";
ko.extenders.passwordValidator = (target) => {
target.extend({
validation: {
validator: (value) => {
var minLength = 8;
Fixed Show fixed Hide fixed
var requiredCategories = 2;
Fixed Show fixed Hide fixed
var uppercaseRegex = /[A-Z]/;
Fixed Show fixed Hide fixed
var lowercaseRegex = /[a-z]/;
Fixed Show fixed Hide fixed
var numbersRegex = /[0-9]/;
Fixed Show fixed Hide fixed
var symbolsRegex = new RegExp("[!@#$%^&*()_+{}\\[\\]:;<>,.?~\\-]");
Fixed Show fixed Hide fixed
var categories = 0;
Fixed Show fixed Hide fixed
if (uppercaseRegex.test(value)) categories++;
if (lowercaseRegex.test(value)) categories++;
if (numbersRegex.test(value)) categories++;
if (symbolsRegex.test(value)) categories++;
var isValid = value.length >= minLength && categories >= requiredCategories;
Fixed Show fixed Hide fixed
return isValid;
},
message: ValidationMessages.passwordCriteria
}
});
return target;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@
<!-- ko if: !isChangeConfirmed() -->
<form data-bind="submit: changePassword">
<fieldset data-bind="attr: { disabled: working}">
<div class="form-group">
<div class="form-group has-validation">
<label for="password">Password *</label>
<input aria-required="true" class="form-control" id="password" name="password"
autocomplete="password" type="password" data-bind="textInput: password">
<input aria-required="true" class="form-control" id="password" name="password" autocomplete="password"
type="password" data-bind="textInput: password">
<span class="invalid-feedback" data-bind="validationMessage: password"></span>
</div>
<div class="form-group">
<div class="form-group has-validation">
<label for="new-password">New password *</label>
<input aria-required="true" class="form-control" id="new-password" name="new-password"
autocomplete="new-password" type="password" data-bind="textInput: newPassword">
<span class="invalid-feedback" data-bind="validationMessage: newPassword"></span>
</div>
<div class="form-group">
<div class="form-group has-validation">
<label for="confirmPassword">Confirm password *</label>
<input aria-required="true" class="form-control" id="confirmPassword" name="confirm"
autocomplete="new-password" type="password"
data-bind="textInput: passwordConfirmation">
autocomplete="new-password" type="password" data-bind="textInput: passwordConfirmation">
<span class="invalid-feedback" data-bind="validationMessage: passwordConfirmation"></span>
</div>
<!-- ko if: requireHipCaptcha -->
<hip-captcha params="{ captchaData: captchaData, onInitComplete: onCaptchaCreated }"></hip-captcha>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export class ChangePassword {
decorateInputElement: true
});

this.password.extend(<any>{ required: { message: ValidationMessages.passwordRequired } }); // TODO: password requirements should come from Management API.
this.newPassword.extend(<any>{ required: { message: ValidationMessages.newPasswordRequired }, minLength: 8 }); // TODO: password requirements should come from Management API.
this.password.extend(<any>{ required: { message: ValidationMessages.passwordRequired } });
this.newPassword.extend(<any>{ required: { message: ValidationMessages.newPasswordRequired }, passwordValidator: {} });
this.passwordConfirmation.extend(<any>{ equal: { message: ValidationMessages.passwordConfirmationMustMatch, params: this.newPassword } });
this.captcha.extend(<any>{ required: { message: ValidationMessages.captchaRequired } });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@
<form data-bind="submit: resetPswd">

<fieldset>
<div class="form-group">
<div class="form-group has-validation">
<label for="password">Password</label>
<input aria-required="true" class="form-control" id="password" name="password"
autocomplete="new-password" type="password" data-bind="textInput: password">
<input aria-required="true" class="form-control" id="password" name="password" autocomplete="new-password"
type="password" data-bind="textInput: password">
<span class="invalid-feedback" data-bind="validationMessage: password"></span>
</div>
<div class="form-group">
<div class="form-group has-validation">
<label for="confirmPassword">Confirm password</label>
<input aria-required="true" class="form-control" id="confirmPassword" name="confirm"
autocomplete="new-password" type="password"
data-bind="textInput: passwordConfirmation">
autocomplete="new-password" type="password" data-bind="textInput: passwordConfirmation">
<span class="invalid-feedback" data-bind="validationMessage: passwordConfirmation"></span>
</div>

<div class="form-group">
<button type="submit" id="signup" class="button button-primary">
<button type="submit" id="signup" class="button button-primary"
data-bind="attr: { disabled: isResetPasswordDisabled() }">
Reset
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ConfirmPassword {
decorateInputElement: true
});

this.password.extend(<any>{ required: { message: ValidationMessages.passwordRequired }, minLength: 8 }); // TODO: password requirements should come from Management API.
this.password.extend(<any>{ required: { message: ValidationMessages.passwordRequired }, passwordValidator: {} });
this.passwordConfirmation.extend(<any>{ equal: { message: ValidationMessages.passwordConfirmationMustMatch, params: this.password } });
}

Expand Down
44 changes: 25 additions & 19 deletions src/components/users/signup/ko/runtime/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,49 @@
<!-- ko ifnot: isUserRequested -->
<form data-bind="submit: signup">
<fieldset data-bind="attr: { disabled: working}">
<div class="form-group">
<div class="form-group has-validation">
<label for="email">Email *</label>
<input aria-required="true" autofocus="autofocus" spellcheck="false" class="form-control" id="email" name="email"
autocomplete="email" placeholder="e.g. [email protected]" type="email" data-bind="textInput: email">
<input aria-required="true" autofocus="autofocus" spellcheck="false" class="form-control" id="email"
name="email" autocomplete="email" placeholder="e.g. [email protected]" type="email"
data-bind="textInput: email">
<span class="invalid-feedback" data-bind="validationMessage: email"></span>
</div>
<div class="form-group">
<div class="form-group has-validation">
<label for="password">Password *</label>
<input aria-required="true" class="form-control" id="password" name="password"
autocomplete="new-password" type="password" data-bind="textInput: password">
<input aria-required="true" class="form-control" id="password" name="password" autocomplete="new-password"
type="password" data-bind="textInput: password">
<span class="invalid-feedback" data-bind="validationMessage: password"></span>
</div>
<div class="form-group">
<div class="form-group has-validation">
<label for="confirmPassword">Confirm password *</label>
<input aria-required="true" class="form-control" id="confirmPassword" name="confirm"
autocomplete="new-password" type="password"
data-bind="textInput: passwordConfirmation">
autocomplete="new-password" type="password" data-bind="textInput: passwordConfirmation">
<span class="invalid-feedback" data-bind="validationMessage: passwordConfirmation"></span>
</div>
<div class="form-group">
<div class="form-group has-validation">
<label for="firstName">First name *</label>
<input aria-required="true" class="form-control" id="firstName" name="firstName"
placeholder="e.g. John" type="text" data-bind="textInput: firstName">
<input aria-required="true" class="form-control" id="firstName" name="firstName" placeholder="e.g. John"
type="text" data-bind="textInput: firstName">
<span class="invalid-feedback" data-bind="validationMessage: firstName"></span>
</div>
<div class="form-group">
<div class="form-group has-validation">
<label for="lastName">Last name *</label>
<input aria-required="true" class="form-control" id="lastName" name="lastName"
placeholder="e.g. Doe" type="text" data-bind="textInput: lastName">
<input aria-required="true" class="form-control" id="lastName" name="lastName" placeholder="e.g. Doe"
type="text" data-bind="textInput: lastName">
<span class="invalid-feedback" data-bind="validationMessage: lastName"></span>
</div>

<!-- ko if: requireHipCaptcha -->
<hip-captcha params="{ captchaData: captchaData, onInitComplete: onCaptchaCreated }"></hip-captcha>
<!-- /ko -->
<!-- /ko -->

<!-- ko if: termsEnabled && termsOfUse -->
<terms-of-use params="{ isConsentRequired: isConsentRequired, consented: consented, termsOfUse: termsOfUse }"></terms-of-use>
<terms-of-use
params="{ isConsentRequired: isConsentRequired, consented: consented, termsOfUse: termsOfUse }"></terms-of-use>
<!-- /ko -->

<div class="form-group">

<!-- ko ifnot: working -->
<button type="button" id="signup" class="button button-primary" data-bind="click: signup">
Sign up
Expand Down
4 changes: 2 additions & 2 deletions src/components/users/signup/ko/runtime/signup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class Signup {
});

this.email.extend(<any>{ required: { message: ValidationMessages.emailRequired }, email: true });
this.password.extend(<any>{ required: { message: ValidationMessages.passwordRequired }, minLength: 8 }); // TODO: password requirements should come from Management API.
// this.password.extend(<any>{ required: { message: ValidationMessages.passwordRequired }, passwordValidator: {} });
this.passwordConfirmation.extend(<any>{ equal: { message: ValidationMessages.passwordConfirmationMustMatch, params: this.password } });
this.firstName.extend(<any>{ required: { message: ValidationMessages.firstNameRequired } });
this.lastName.extend(<any>{ required: { message: ValidationMessages.lastNameRequired } });
Expand Down Expand Up @@ -155,7 +155,7 @@ export class Signup {
if (captchaIsRequired) {
if (!this.setCaptchaValidation) {
this.logger.trackEvent("CaptchaValidation", { message: "Captcha failed to initialize." });
dispatchErrors(this.eventManager, ErrorSources.resetpassword, [ValidationMessages.captchaNotInitialized]);
dispatchErrors(this.eventManager, ErrorSources.signup, [ValidationMessages.captchaNotInitialized]);
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/components/users/validationMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export class ValidationMessages {
static firstNameRequired = `First name is required.`;
static lastNameRequired = `Last name is required.`;
static passwordRequired = `Password is required.`;
static passwordCriteria = `Passwords must have at least 8 characters and contain at least two of the following: uppercase letters, lowercase letters, numbers, and symbols`;
static passwordConfirmationMustMatch = `Password confirmation field must be equal to password.`;
static newPasswordRequired = `New password is required.`;
static consentRequired = `You must agree to the terms of use.`;
Expand Down