Skip to content

Commit 151a5a4

Browse files
committed
LUI-83 : Displaying meaningful info when user is locked out
Displaying meaningful infowen user is locked made the variable local displaying use ful info when user is locked out
1 parent 521d14f commit 151a5a4

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

api/src/main/resources/messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ legacyui.manageuser.noProviderIdentifier=No Identifier Specified
1010
${project.parent.artifactId}.Location.purgeLocation=Permanently Delete Location
1111
${project.parent.artifactId}.Location.confirmDelete=Are you sure you want to delete this Location? It will be permanently removed from the system.
1212
${project.parent.artifactId}.Location.purgedSuccessfully=Location deleted successfully
13+
14+
legacyui.lockedOutMessage=You have attempted to log in too many times and have been Locked out. Please try again later in 5 minutes

omod/src/main/java/org/openmrs/web/servlet/LoginServlet.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,20 @@ public class LoginServlet extends HttpServlet {
6565
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
6666
* javax.servlet.http.HttpServletResponse)
6767
*/
68+
6869
@Override
6970
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
7071
HttpSession httpSession = request.getSession();
7172

73+
Integer loginAttemptsByUser;
7274
String ipAddress = request.getRemoteAddr();
7375
Integer loginAttempts = loginAttemptsByIP.get(ipAddress);
7476
if (loginAttempts == null) {
7577
loginAttempts = 1;
7678
}
7779

7880
loginAttempts++;
79-
81+
loginAttemptsByUser = loginAttempts - 1;
8082
boolean lockedOut = false;
8183
// look up the allowed # of attempts per IP
8284
Integer allowedLockoutAttempts = 100;
@@ -178,7 +180,14 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
178180
catch (ContextAuthenticationException e) {
179181
// set the error message for the user telling them
180182
// to try again
181-
httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "auth.password.invalid");
183+
Integer maximumAlowedAttempts = 7;
184+
if (loginAttemptsByUser <= maximumAlowedAttempts) {
185+
httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "auth.password.invalid");
186+
}
187+
188+
if (loginAttemptsByUser > maximumAlowedAttempts) {
189+
httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "legacyui.lockedOutMessage");
190+
}
182191
}
183192

184193
}

0 commit comments

Comments
 (0)