onValidate-user-sensitive-fields.js revision 35d8f970e25366e2703f1dacbf8fe3f55b494be1
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright © 2011-2012 ForgeRock AS. All rights reserved.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at http://forgerock.org/license/CDDLv1.0.html
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @author jdabrowski
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This script validates if user is valid.
c6c8bcf74a1e796c167156af1cc1a5d95c67aceaRobert Wapshottfunction requiredValidator(toValidate, fieldName) {
c6c8bcf74a1e796c167156af1cc1a5d95c67aceaRobert Wapshott return false;
c6c8bcf74a1e796c167156af1cc1a5d95c67aceaRobert Wapshottfunction atLeastLengthValidator(toValidate, minLength, fieldName) {
c6c8bcf74a1e796c167156af1cc1a5d95c67aceaRobert Wapshott errors.push(fieldName + " should have at least " + minLength + " characters");
6309b849c2de831a0eaed9c27b5794bed9bd8fd1Neil Maddenfunction alLeastOneNumberValidator(toValidate, fieldName) {
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott errors.push(fieldName + " should have at least one number");
a90aba9cbcbb8e7fe95e45590d853959efe0d354Tom Rumseyfunction alLeastOneCapitalCharValidator(toValidate, fieldName) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster var reg = /[(A-Z)]+/;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster errors.push(fieldName + " should have at least one capital letter");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfunction requiredOnlyAlfabeticalValidator(toValidate, fieldName) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster var exists = requiredValidator(toValidate, fieldName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster var reg = /^([A-Za-\u0105\u0107\u0119\u0142\u00F3\u015B\u017C\u017A\u0104\u0106\u0118\u0141\u00D3\u015A\u017B\u0179\u00C0\u00C8\u00CC\u00D2\u00D9\u00E0\u00E8\u00EC\u00F2\u00F9\u00C1\u00C9\u00CD\u00D3\u00DA\u00DD\u00E1\u00E9\u00ED\u00F3\u00FA\u00FD\u00C2\u00CA\u00CE\u00D4\u00DB\u00E2\u00EA\u00EE\u00F4\u00FB\u00C3\u00D1\u00D5\u00E3\u00F1\u00F5\u00C4\u00CB\u00CF\u00D6\u00DC\u0178\u00E4\u00EB\u00EF\u00F6\u00FC\u0178\u00A1\u00BF\u00E7\u00C7\u0152\u0153\u00DF\u00D8\u00F8\u00C5\u00E5\u00C6\u00E6\u00DE\u00FE\u00D0\u00F0\-\s])+$/;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster errors.push("Only alphabetic characters allowed in " + fieldName);
a19a421277791c670d5a4ebcd6d7af7de159d271Tom Rumseyfunction numbersAndSpecialCharsValidator(toValidate, fieldName) {
a19a421277791c670d5a4ebcd6d7af7de159d271Tom Rumsey var exists = requiredValidator(toValidate, fieldName);
a19a421277791c670d5a4ebcd6d7af7de159d271Tom Rumsey errors.push("Only numbers and special characters allowed in " + fieldName);
a19a421277791c670d5a4ebcd6d7af7de159d271Tom Rumseyfunction requiredEmailValidator(toValidate, fieldName) {
a19a421277791c670d5a4ebcd6d7af7de159d271Tom Rumsey var exists = requiredValidator(toValidate, fieldName);
a19a421277791c670d5a4ebcd6d7af7de159d271Tom Rumsey var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterfunction requiredPasswordValidator(toValidate, fieldName) {
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott var exists = requiredValidator(toValidate, fieldName);
6309b849c2de831a0eaed9c27b5794bed9bd8fd1Neil Madden atLeastLengthValidator(toValidate, 8, fieldName);
a90aba9cbcbb8e7fe95e45590d853959efe0d354Tom Rumsey alLeastOneNumberValidator(toValidate, fieldName);
a90aba9cbcbb8e7fe95e45590d853959efe0d354Tom Rumsey alLeastOneCapitalCharValidator(toValidate, fieldName);
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshottfunction notEqualValidator(firstVal, secondVal, message) {
35ab1c5bca11317474fe12bdd8d22c17cdaf2697Robert Wapshott requiredOnlyAlfabeticalValidator(user.givenName, "Given name");
6309b849c2de831a0eaed9c27b5794bed9bd8fd1Neil Madden requiredOnlyAlfabeticalValidator(user.familyName, "Family name");
a90aba9cbcbb8e7fe95e45590d853959efe0d354Tom Rumsey numbersAndSpecialCharsValidator(user.phoneNumber, "Mobile Phone Number");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster requiredEmailValidator(user.userName, "UserName");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster requiredPasswordValidator(user.password, "Password");
c6c8bcf74a1e796c167156af1cc1a5d95c67aceaRobert Wapshott notEqualValidator(user.userName, user.password, "UserName and Password cannot be equal");
c6c8bcf74a1e796c167156af1cc1a5d95c67aceaRobert Wapshott requiredValidator(user.securityQuestion, "Security Question");
c6c8bcf74a1e796c167156af1cc1a5d95c67aceaRobert Wapshott requiredValidator(user.securityAnswer, "Security Answer");
c6c8bcf74a1e796c167156af1cc1a5d95c67aceaRobert Wapshott//TODO Backend validation defined here supports specific data format required by the default OpenIDM UI. If OpenIDM is used only with default UI this line can be uncommented to ensure proper stored data format.
c6c8bcf74a1e796c167156af1cc1a5d95c67aceaRobert Wapshott//isUserValid();