Search in sources :

Example 1 with I_AD_User

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;
}
Also used : I_AD_User(org.compiere.model.I_AD_User) AdempierePOSException(org.adempiere.pos.AdempierePOSException) MUser(org.compiere.model.MUser)

Aggregations

AdempierePOSException (org.adempiere.pos.AdempierePOSException)1 I_AD_User (org.compiere.model.I_AD_User)1 MUser (org.compiere.model.MUser)1