Custom Password Policy Validation in OpenIDM

A customer needed to ensure that passwords contained at least one ‘special character’ when a new password was created in OpenIDM.

I borrowed heavily from the provided samples but had to figure out the correct regexp formatting.

Here is the function that I used to implement this:

function atLeastXSpecialChars(fullObject, value, params, property) {
   isRequired = _.find(this.failedPolicyRequirements, function (fpr) {
       return fpr.policyRequirement === "REQUIRED";
   isNonEmptyString = (typeof(value) === "string" && value.length),
   valuePassesRegexp = (function (v) {
   var testResult = isNonEmptyString ? v.match(/\(|\)|\!|\$|\`|\~|\:|\.|\,|\<|\>|\=|\?|\^|\_|\{|\}/g) : false;
       return testResult;
   if ((isRequired || isNonEmptyString) && !valuePassesRegexp) {
       return [ {"policyRequirement" : "AT_LEAST_X_SPECIAL_CHARS"}];
    return [];

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top