The CreatorCon Call for Content is officially open! Get started here.

Custom Password Strength Check

SandeepKSingh
Kilo Sage

Scenario:

I am asked to develop a Script Include that validates the password strength based on the following conditions:

  1. Minimum length: 8 characters

  2. Must contain at least one uppercase letter

  3. Must contain at least one lowercase letter

  4. Must contain at least one number

  5. Must contain at least one special character

If the password does not meet these requirements, it should be flagged as “Weak Password”, otherwise as “Strong Password.”


How we can achieve this ?

3 ACCEPTED SOLUTIONS

vignesh parthib
Tera Guru

Hi @SandeepKSingh 

 

If your looking for custom approach, you can try this

 

function validatePasswordStrength(password) {
    // Regular expressions for validation
    var minLength = password.length >= 8;
    var hasUppercase = /[A-Z]/.test(password);
    var hasLowercase = /[a-z]/.test(password);
    var hasNumber = /[0-9]/.test(password);
    var hasSpecialChar = /[!@#$%^&*(),.?":{}|<>]/.test(password);

    if (minLength && hasUppercase && hasLowercase && hasNumber && hasSpecialChar) {
        return "Strong Password";
    } else {
        return "Weak Password";
    }
}

 

Thanks,
Vignesh
"If this solution resolves your issue, kindly mark it as correct."

View solution in original post

Bhuvan
Mega Patron

@SandeepKSingh 

 

Can you try the following for scripting,

 

https://www.servicenow.com/docs/bundle/washingtondc-platform-security/page/script/server-scripting/t...

 

You can configure the validation using Policies for latest release,

 

https://www.servicenow.com/docs/bundle/zurich-platform-security/page/integrate/authentication/task/e...

 

If this helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan

View solution in original post

Ravi Gaurav
Giga Sage
Giga Sage

Hi @SandeepKSingh 

 

you can use the below in script include:-

 

ckStr: function(pwd) {
if (!pwd) return "Empty password!";

var strong = pwd.length >= 8 &&
/[A-Z]/.test(pwd) &&
/[a-z]/.test(pwd) &&
/[0-9]/.test(pwd) &&
/[^A-Za-z0-9]/.test(pwd);

return strong ? "Strong Password" : "Weak Password";
},

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

View solution in original post

4 REPLIES 4

vignesh parthib
Tera Guru

Hi @SandeepKSingh 

 

If your looking for custom approach, you can try this

 

function validatePasswordStrength(password) {
    // Regular expressions for validation
    var minLength = password.length >= 8;
    var hasUppercase = /[A-Z]/.test(password);
    var hasLowercase = /[a-z]/.test(password);
    var hasNumber = /[0-9]/.test(password);
    var hasSpecialChar = /[!@#$%^&*(),.?":{}|<>]/.test(password);

    if (minLength && hasUppercase && hasLowercase && hasNumber && hasSpecialChar) {
        return "Strong Password";
    } else {
        return "Weak Password";
    }
}

 

Thanks,
Vignesh
"If this solution resolves your issue, kindly mark it as correct."

Bhuvan
Mega Patron

@SandeepKSingh 

 

Can you try the following for scripting,

 

https://www.servicenow.com/docs/bundle/washingtondc-platform-security/page/script/server-scripting/t...

 

You can configure the validation using Policies for latest release,

 

https://www.servicenow.com/docs/bundle/zurich-platform-security/page/integrate/authentication/task/e...

 

If this helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan

Ankur Bawiskar
Tera Patron
Tera Patron

@SandeepKSingh 

no scripting required, you can handle this with OOTB configuration

Configure the required strength for passwords 

Configure your password policy 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ravi Gaurav
Giga Sage
Giga Sage

Hi @SandeepKSingh 

 

you can use the below in script include:-

 

ckStr: function(pwd) {
if (!pwd) return "Empty password!";

var strong = pwd.length >= 8 &&
/[A-Z]/.test(pwd) &&
/[a-z]/.test(pwd) &&
/[0-9]/.test(pwd) &&
/[^A-Za-z0-9]/.test(pwd);

return strong ? "Strong Password" : "Weak Password";
},

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/