diff --git a/Server-Side Components/Script Includes/Password Strength Checker/README.MD b/Server-Side Components/Script Includes/Password Strength Checker/README.MD new file mode 100644 index 0000000000..8bef91c8b6 --- /dev/null +++ b/Server-Side Components/Script Includes/Password Strength Checker/README.MD @@ -0,0 +1,17 @@ +This repository contains a ServiceNow Script Include + Client Script demo for enforcing password strength during user registration or password reset processes. +Overview + +The goal is to ensure that any password set in ServiceNow (e.g., through a Catalog Item or custom form) follows strong security rules: +At least 8 characters +At least 1 uppercase letter +At least 1 lowercase letter +At least 1 number +At least 1 special character +If the rules are not met, the system flags the password as Weak Password. + +Example : +Imagine you build a User Registration Catalog Item where a field Proposed Password is entered by the user. +On change of this field, the Client Script runs. +It calls the PasswordUtil Script Include. +If the password is weak, the form shows an inline error message, preventing weak password submissions. +This ensures consistent security enforcement across ServiceNow forms. diff --git a/Server-Side Components/Script Includes/Password Strength Checker/password.js b/Server-Side Components/Script Includes/Password Strength Checker/password.js new file mode 100644 index 0000000000..0c11ef858d --- /dev/null +++ b/Server-Side Components/Script Includes/Password Strength Checker/password.js @@ -0,0 +1,31 @@ +// Class definition +var PasswordUtil = Class.create(); +PasswordUtil.prototype = { + initialize: function() {}, + + /** + * checkStrength + * @param {String} pwd - The password string to evaluate + * @return {String} result - Returns "Strong Password" or "Weak Password" + */ + checkStrength: function(pwd) { + // If password is empty/null, return message + if (!pwd) return "Empty password!"; + + // Rules for strong password: + // 1. At least 8 characters + // 2. At least one uppercase letter + // 3. At least one lowercase letter + // 4. At least one number + // 5. At least one special character + var strong = pwd.length >= 8 && + /[A-Z]/.test(pwd) && // has uppercase + /[a-z]/.test(pwd) && // has lowercase + /[0-9]/.test(pwd) && // has number + /[^A-Za-z0-9]/.test(pwd); // has special char + + return strong ? "Strong Password" : "Weak Password"; + }, + + type: 'PasswordUtil' +};