Skip to content

Commit 77863c2

Browse files
authored
Password validation script (#1429)
* Script.js * readme.md
1 parent 840009f commit 77863c2

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function onSubmit() {
2+
// Get the password value from the field
3+
var password = g_form.getValue('password'); // Change 'password' to your field name
4+
// Get the first and last name values from the fields
5+
var firstName = g_form.getValue('first_name'); // Change 'first_name' to your field name
6+
var lastName = g_form.getValue('last_name'); // Change 'last_name' to your field name
7+
// Define the regex pattern for a strong password
8+
var passwordPattern = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
9+
10+
// Check if the password contains the first or last name
11+
if (password.includes(firstName) || password.includes(lastName)) {
12+
// Display an error message if validation fails
13+
g_form.showFieldMsg('password', 'Password cannot contain your first or last name.', 'error');
14+
return false; // Prevent form submission
15+
}
16+
// Validate the password against the pattern
17+
if (!passwordPattern.test(password)) {
18+
// Display an error message if validation fails
19+
g_form.showFieldMsg('password', 'Password must be at least 8 characters long, contain at least one uppercase letter, one lowercase letter, one digit, and one special character.', 'error');
20+
return false; // Prevent form submission
21+
}
22+
23+
24+
return true; // Allow form submission if all validations pass
25+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Description of the Combined Password Validation Script
2+
Purpose
3+
The script validates the password entered by the user in a ServiceNow catalog item form. It ensures that the password meets strong security criteria and does not include the user's first or last name, enhancing overall security.
4+
5+
Validation Criteria
6+
Strong Password Requirements:
7+
8+
At least 8 characters long.
9+
Contains at least one uppercase letter.
10+
Contains at least one lowercase letter.
11+
Contains at least one digit.
12+
Contains at least one special character (e.g., @$!%*?&).
13+
First and Last Name Restrictions:
14+
15+
The password cannot contain the user's first name or last name.

0 commit comments

Comments
 (0)