Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,83 +171,12 @@ public String userAuthenticate(
}

String decryptPassword = aesUtil.decrypt("Piramal12Piramal", m_User.getPassword());
// Fetch user
List<User> existingUser = iemrAdminUserServiceImpl.userExitsCheck(m_User.getUserName());

/*
* =========================================
* ACCOUNT LOCK CHECK
* =========================================
*/
if(!existingUser.isEmpty()){
if (existingUser.get(0) != null
&& existingUser.get(0).getFailedAttempt() != null
&& existingUser.get(0).getFailedAttempt() >= 5) {

throw new IEMRException(
"Your account has been locked due to multiple failed login attempts. Please contact administrator.");
}
}


List<User> mUser = iemrAdminUserServiceImpl
.userAuthenticate(m_User.getUserName(), decryptPassword);

/*
* =========================================
* FAILED LOGIN ATTEMPT LOGIC
* =========================================
*/
if(!existingUser.isEmpty()){
if (existingUser != null) {

Integer failedAttempt = existingUser.get(0).getFailedAttempt() != null
? existingUser.get(0).getFailedAttempt()
: 0;

failedAttempt++;

existingUser.get(0).setFailedAttempt(failedAttempt);

iemrAdminUserServiceImpl.save(existingUser.get(0));

int remainingAttempts = 5 - failedAttempt;

// Lock account on 5th attempt
if (failedAttempt >= 5) {



response.setError(new IEMRException(
"Your account has been locked due to multiple failed login attempts."));
return response.toString();
}

// Warning on 3rd attempt
if (failedAttempt == 4) {


response.setError(new IEMRException(
"Invalid username or password. Remaining attempts: "
+ remainingAttempts
+ ". If you enter wrong username or password again, your account will be locked."));
return response.toString();
}


response.setError(new IEMRException(
"Invalid username or password. Remaining attempts: "
+ remainingAttempts));
return response.toString();

}
}

/*
* =========================================
* RESET FAILED ATTEMPTS ON SUCCESS LOGIN
* =========================================
*/
User loggedInUser = mUser.get(0);

loggedInUser.setFailedAttempt(0);
Expand Down
Loading