Skip to content

Commit 818257c

Browse files
fix issue of feature multiple login attempt
1 parent fee73b3 commit 818257c

1 file changed

Lines changed: 6 additions & 22 deletions

File tree

src/main/java/com/iemr/common/service/users/IEMRAdminUserServiceImpl.java

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -265,43 +265,27 @@ public List<User> userAuthenticate(String userName, String password) throws Exce
265265
checkUserAccountStatus(user);
266266
iEMRUserRepositoryCustom.save(user);
267267
} else if (validatePassword == 0) {
268-
int currentFailedAttempt =
269-
user.getFailedAttempt() != null ? user.getFailedAttempt() : 0;
270-
271-
int newFailedAttempt = currentFailedAttempt + 1;
272-
int remainingAttempts = failedAttempt - newFailedAttempt;
273-
if (newFailedAttempt < failedAttempt) {
274-
275-
user.setFailedAttempt(newFailedAttempt);
268+
if (user.getFailedAttempt() + 1 < failedAttempt) {
269+
user.setFailedAttempt(user.getFailedAttempt() + 1);
276270
user = iEMRUserRepositoryCustom.save(user);
277-
278271
logger.warn("User Password Wrong");
279-
280-
if (remainingAttempts == 1) {
281-
throw new IEMRException(
282-
"Invalid username or password. Remaining attempts: 1. "
283-
+ "If you enter wrong username or password again, your account will be locked.");
284-
}
285-
286-
throw new IEMRException(
287-
"Invalid username or password. Remaining attempts: "
288-
+ remainingAttempts);
289-
}else if (user.getFailedAttempt() + 1 >= failedAttempt) {
272+
throw new IEMRException("Invalid username or password");
273+
} else if (user.getFailedAttempt() + 1 >= failedAttempt) {
290274
user.setFailedAttempt(user.getFailedAttempt() + 1);
291275
user.setDeleted(true);
292276
user = iEMRUserRepositoryCustom.save(user);
293277
logger.warn("User Account has been locked after reaching the limit of {} failed login attempts.",
294278
ConfigProperties.getInteger("failedLoginAttempt"));
295279

296280
throw new IEMRException(
297-
"Your account has been locked due to multiple failed login attempts. Please contact administrator.");
281+
"Invalid username or password. Please contact administrator.");
298282
} else {
299283
user.setFailedAttempt(user.getFailedAttempt() + 1);
300284
user = iEMRUserRepositoryCustom.save(user);
301285
logger.warn("Failed login attempt {} of {} for a user account.",
302286
user.getFailedAttempt(), ConfigProperties.getInteger("failedLoginAttempt"));
303287
throw new IEMRException(
304-
"Your account has been locked due to multiple failed login attempts. Please contact administrator.");
288+
"Invalid username or password. Please contact administrator.");
305289
}
306290
} else {
307291
checkUserAccountStatus(user);

0 commit comments

Comments
 (0)