use of org.compiere.model.I_AD_User in project adempiere by adempiere.
the class CPOS method isValidUserPin.
/**
* Validate User PIN
* @param userPin
*/
public boolean isValidUserPin(char[] userPin) {
if (userPin == null || userPin.length == 0)
return false;
MUser user = MUser.get(getCtx(), getAD_User_ID());
Optional<I_AD_User> optionalSuperVisor = Optional.of(user.getSupervisor());
I_AD_User superVisor = optionalSuperVisor.orElseThrow(() -> new AdempierePOSException("@Supervisor@ @NotFound@"));
Optional<String> superVisorName = Optional.ofNullable(superVisor.getName());
if (superVisor.getUserPIN() == null || superVisor.getUserPIN().isEmpty())
throw new AdempierePOSException("@Supervisor@ \"" + superVisorName.orElse("") + "\": @UserPIN@ @NotFound@");
char[] correctPassword = superVisor.getUserPIN().toCharArray();
boolean isCorrect = true;
if (userPin.length != correctPassword.length) {
isCorrect = false;
} else {
for (int i = 0; i < userPin.length; i++) {
if (userPin[i] != correctPassword[i]) {
isCorrect = false;
}
}
}
//Zero out the password.
for (int i = 0; i < correctPassword.length; i++) {
correctPassword[i] = 0;
}
return isCorrect;
}
Aggregations