Search in sources :

Example 1 with NoConsoleException

use of es.gob.jmulticard.ui.passwordcallback.NoConsoleException in project jmulticard by ctt-gob-es.

the class ConsolePasswordCallback method getPassword.

/**
 * {@inheritDoc}
 */
@Override
public char[] getPassword() {
    Console console = System.console();
    if (console == null) {
        // $NON-NLS-1$
        throw new NoConsoleException("No hay consola para solicitar el PIN");
    }
    // $NON-NLS-1$
    final char[] password = console.readPassword(removeHTML(this.prompt) + ":\n");
    if (password == null) {
        throw new CancelledOperationException(// $NON-NLS-1$
        "Se ha cancelado la introduccion de PIN en consola");
    }
    if (password.length < 8 || password.length > 16) {
        // $NON-NLS-1$ //$NON-NLS-2$
        console.printf(Messages.getString("ConsolePasswordCallback.1") + "\n");
        for (int i = 0; i < password.length; i++) {
            password[i] = '\0';
        }
        return getPassword();
    }
    console.flush();
    console = null;
    return password;
}
Also used : CancelledOperationException(es.gob.jmulticard.CancelledOperationException) Console(java.io.Console) NoConsoleException(es.gob.jmulticard.ui.passwordcallback.NoConsoleException)

Aggregations

CancelledOperationException (es.gob.jmulticard.CancelledOperationException)1 NoConsoleException (es.gob.jmulticard.ui.passwordcallback.NoConsoleException)1 Console (java.io.Console)1