|
3 | 3 | <@layout.registrationLayout displayMessage=!messagesPerField.existsError('password','password-confirm'); section>
|
4 | 4 | <#if section = "header">
|
5 | 5 | ${msg("updatePasswordTitle")}
|
| 6 | + <div id="password-error-message" class="kcErrorMessage" style="display:none;"> |
| 7 | + <p class="error-text"></p> |
| 8 | +</div> |
6 | 9 | <#elseif section = "form">
|
7 |
| - <form id="kc-passwd-update-form" class="${properties.kcFormClass!}" action="${url.loginAction}" method="post" onsubmit="return checkPassword()"> |
| 10 | + <form id="kc-passwd-update-form" class="${properties.kcFormClass!}" action="${url.loginAction}" method="post" onsubmit="return checkPasswordBlacklist()"> |
8 | 11 | <input type="text" id="username" name="username" value="${username}" autocomplete="username"
|
9 | 12 | readonly="readonly" style="display:none;"/>
|
10 | 13 | <input type="password" id="password" name="password" autocomplete="current-password" style="display:none;"/>
|
|
67 | 70 |
|
68 | 71 |
|
69 | 72 | <script type="text/javascript">
|
70 |
| - // List of blacklisted passwords (can be expanded or fetched from an API) |
71 |
| - const blacklistedPasswords = [ |
72 |
| - 'password123', 'admin', 'qwerty', '123456', 'letmein' |
73 |
| - ]; |
| 73 | + let blacklistedPasswords = []; |
74 | 74 |
|
75 |
| - // Function to check if the entered password is blacklisted |
76 |
| - function checkPassword() { |
| 75 | + function loadBlacklist() { |
| 76 | + fetch('https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/10-million-password-list-top-1000000.txt') |
| 77 | + .then(response => response.text()) |
| 78 | + .then(data => { |
| 79 | + blacklistedPasswords = data.split("\n"); |
| 80 | + blacklistedPasswords = blacklistedPasswords.filter(password => password.length >= 8); |
| 81 | + }) |
| 82 | + .catch(error => { |
| 83 | + console.error("could not get blacklist", error); |
| 84 | + }); |
| 85 | + } |
| 86 | +
|
| 87 | + loadBlacklist(); |
| 88 | +
|
| 89 | + function checkPasswordBlacklist() { |
77 | 90 | var password = document.getElementById("password-new").value;
|
78 | 91 |
|
79 | 92 | if (blacklistedPasswords.includes(password)) {
|
80 |
| - alert("This password is blacklisted. Please choose a different one."); |
81 |
| - return false; // Prevent form submission |
82 |
| - } |
83 |
| -
|
84 |
| - var confirmPassword = document.getElementById("password-confirm").value; |
85 |
| - |
86 |
| - if (password !== confirmPassword) { |
87 |
| - alert("Passwords do not match."); |
88 |
| - return false; // Prevent form submission |
| 93 | + var errorMessageDiv = document.getElementById("password-error-message"); |
| 94 | + var errorText = document.querySelector(".kcErrorMessage .error-text"); |
| 95 | + errorText.textContent = "Password is commonly used."; |
| 96 | + errorMessageDiv.style.display = "block"; |
| 97 | + return false; |
89 | 98 | }
|
90 | 99 |
|
91 |
| - return true; // Allow form submission |
| 100 | + var errorMessageDiv = document.getElementById("password-error-message"); |
| 101 | + errorMessageDiv.style.display = "none"; |
| 102 | + return true; |
92 | 103 | }
|
93 | 104 | </script>
|
94 | 105 | </form>
|
|
0 commit comments