Skip to content

Commit 0bf63e5

Browse files
Create password.js
This Script Include validates the strength of a password. It can be used in scenarios like: User self-registration (ensuring strong password before allowing submission). Custom portal forms (when users create accounts or update passwords). Service Desk workflows (where support staff reset user accounts and must set secure passwords).
1 parent 24c52a3 commit 0bf63e5

File tree

1 file changed

+31
-0
lines changed
  • Server-Side Components/Script Includes/Password Strength Checker

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Class definition
2+
var PasswordUtil = Class.create();
3+
PasswordUtil.prototype = {
4+
initialize: function() {},
5+
6+
/**
7+
* checkStrength
8+
* @param {String} pwd - The password string to evaluate
9+
* @return {String} result - Returns "Strong Password" or "Weak Password"
10+
*/
11+
checkStrength: function(pwd) {
12+
// If password is empty/null, return message
13+
if (!pwd) return "Empty password!";
14+
15+
// Rules for strong password:
16+
// 1. At least 8 characters
17+
// 2. At least one uppercase letter
18+
// 3. At least one lowercase letter
19+
// 4. At least one number
20+
// 5. At least one special character
21+
var strong = pwd.length >= 8 &&
22+
/[A-Z]/.test(pwd) && // has uppercase
23+
/[a-z]/.test(pwd) && // has lowercase
24+
/[0-9]/.test(pwd) && // has number
25+
/[^A-Za-z0-9]/.test(pwd); // has special char
26+
27+
return strong ? "Strong Password" : "Weak Password";
28+
},
29+
30+
type: 'PasswordUtil'
31+
};

0 commit comments

Comments
 (0)