-
Notifications
You must be signed in to change notification settings - Fork 141
fix: added password validation messages #1193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: enext
Are you sure you want to change the base?
Changes from all commits
032ed94
d5e765c
b53d99c
55c29dc
b448f6f
2e99f27
59b8181
09521f9
d0767b3
499158e
a9477e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,13 +37,20 @@ def render(self, name, value, attrs=None, renderer=None): | |
| aria-valuemax="4"> | ||
| </div> | ||
| </div> | ||
| <p class="text-muted password_strength_info d-none"> | ||
| <span style="margin-left:5px;"> | ||
| {message} | ||
| </span> | ||
| </p> | ||
| <div class="password_strength_info d-none"> | ||
| <p class="text-muted mb-0"> | ||
| <span style="margin-left:5px;"> | ||
| {message} | ||
| </span> | ||
| </p> | ||
| </div> | ||
|
Comment on lines
+40
to
+46
|
||
| <div class="password-requirements text-muted small mt-1"> | ||
| <small> | ||
| Password must be at least 8 characters long and contain letters, numbers, and special characters. | ||
| </small> | ||
| </div> | ||
| </div> | ||
| """.format(message=_('This password would take <em class="password_strength_time"></em> to crack.')) | ||
| """.format(message=_('This password would take some time to crack.')) | ||
hemantmm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| self.attrs = add_class(self.attrs, 'password_strength') | ||
| self.attrs['autocomplete'] = 'new-password' | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -42,6 +42,41 @@ const matchPasswords = (passwordField, confirmationFields) => { | |||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| const validatePasswordComplexity = (password) => { | ||||||||||
| const errors = [] | ||||||||||
|
|
||||||||||
| if (password.length < 8) { | ||||||||||
| errors.push("Password must be at least 8 characters long") | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if (!/[a-zA-Z]/.test(password)) { | ||||||||||
| errors.push("Password must contain at least one letter") | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if (!/[0-9]/.test(password)) { | ||||||||||
| errors.push("Password must contain at least one number") | ||||||||||
| } | ||||||||||
|
|
||||||||||
hemantmm marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| if (!/[!@#$%^&*()_\-+=\[\\\]{}|;':",.<>/?`~]/.test(password)) { | ||||||||||
| errors.push("Password must contain at least one special character") | ||||||||||
| } | ||||||||||
|
|
||||||||||
| const commonPasswords = [ | ||||||||||
| "123456", "password", "123456789", "12345678", "12345", "111111", "1234567", "sunshine", "qwerty", "iloveyou", | ||||||||||
| "princess", "admin", "welcome", "666666", "abc123", "football", "123123", "monkey", "654321", "!@#$%^&*", | ||||||||||
| "charlie", "aa123456", "donald", "password1", "qwerty123", "letmein", "1234", "123321", "superman", "hello", | ||||||||||
| "whatever", "michael", "dragon", "baseball", "master", "trustno1", "jordan", "jennifer", "hunter", "cookie", | ||||||||||
| "secret", "mustang", "shadow", "summer", "ashley", "bailey", "passw0rd", "batman", "zaq1zaq1", "qazwsx", | ||||||||||
| "password123", "1q2w3e4r", "qwertyuiop", "123qwe", "123456a", "696969", "qwe123", "1qaz2wsx", "qwerty1", | ||||||||||
| "1234567890", "qwerty12", "123456789a", "password!", "password1234", "password12345", "password123456" | ||||||||||
| ] | ||||||||||
|
Comment on lines
+64
to
+72
|
||||||||||
| if (commonPasswords.includes(password.toLowerCase())) { | ||||||||||
hemantmm marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| errors.push("This password is too common") | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return errors | ||||||||||
| } | ||||||||||
|
|
||||||||||
| const updatePasswordStrength = (passwordField) => { | ||||||||||
| const passwordStrengthBar = passwordField.parentNode.querySelector( | ||||||||||
| ".password_strength_bar", | ||||||||||
|
|
@@ -56,29 +91,70 @@ const updatePasswordStrength = (passwordField) => { | |||||||||
| passwordStrengthBar.style.width = "0%" | ||||||||||
| passwordStrengthBar.setAttribute("aria-valuenow", 0) | ||||||||||
| passwordStrengthInfo.classList.add("d-none") | ||||||||||
| return | ||||||||||
| } | ||||||||||
|
|
||||||||||
| const validationErrors = validatePasswordComplexity(passwordField.value); | ||||||||||
| passwordStrengthInfo.textContent = ""; | ||||||||||
hemantmm marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+97
to
+98
|
||||||||||
| const validationErrors = validatePasswordComplexity(passwordField.value); | |
| passwordStrengthInfo.textContent = ""; | |
| passwordStrengthInfo.textContent = ""; | |
| const validationErrors = validatePasswordComplexity(passwordField.value); |
Uh oh!
There was an error while loading. Please reload this page.