Skip to content

Commit aa9f4d1

Browse files
blacklist added
1 parent 92b9792 commit aa9f4d1

File tree

3 files changed

+44
-18
lines changed

3 files changed

+44
-18
lines changed

keycloak/themes/uid2-theme/login/login-update-password.ftl

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
<@layout.registrationLayout displayMessage=!messagesPerField.existsError('password','password-confirm'); section>
44
<#if section = "header">
55
${msg("updatePasswordTitle")}
6+
<div id="password-error-message" class="kcErrorMessage" style="display:none;">
7+
<p class="error-text"></p>
8+
</div>
69
<#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()">
811
<input type="text" id="username" name="username" value="${username}" autocomplete="username"
912
readonly="readonly" style="display:none;"/>
1013
<input type="password" id="password" name="password" autocomplete="current-password" style="display:none;"/>
@@ -67,28 +70,36 @@
6770

6871

6972
<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 = [];
7474
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() {
7790
var password = document.getElementById("password-new").value;
7891
7992
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;
8998
}
9099
91-
return true; // Allow form submission
100+
var errorMessageDiv = document.getElementById("password-error-message");
101+
errorMessageDiv.style.display = "none";
102+
return true;
92103
}
93104
</script>
94105
</form>

keycloak/themes/uid2-theme/login/messages/messages_en.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ errorPatternNoMatch=We’re sorry, but we only accept sign-ups from company emai
88
forgotPasswordInfo=Enter your email address and we’ll send a link to reset your password.
99
doSendLink=Request Password Reset
1010
emailForgotTitle=Forgot Password
11-
updatePasswordTitle=Set or Update Password Required
11+
updatePasswordTitle=Set New Password Required
1212
doUpdatePassword=Save Password
1313
passwordConfirm=Confirm Password
1414
verifyEmailMessage=To activate your account, verify your email address.

keycloak/themes/uid2-theme/login/resources/css/login.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,19 @@ div.kc-logo-text {
349349
margin-top: 20px;
350350
}
351351

352+
.kcErrorMessage {
353+
margin-top: 15px;
354+
padding: 10px;
355+
background-color: #f8d7da;
356+
color: #721c24;
357+
border: 1px solid #f5c6cb;
358+
border-radius: 5px;
359+
display: none; /* Hidden by default */
360+
}
361+
362+
.kcErrorMessage p {
363+
margin: 0;
364+
font-size: 14px;
365+
}
366+
352367
/* End Recovery codes */

0 commit comments

Comments
 (0)