beryx / text-io

A library for creating interactive console applications in Java
http://text-io.beryx.org/
Apache License 2.0
342 stars 45 forks source link

Input masking doesn't work with SystemTextTerminal #39

Closed RedShift1 closed 2 years ago

RedShift1 commented 2 years ago

Sample code:

import org.beryx.textio.TextIO;
import org.beryx.textio.system.SystemTextTerminal;

public class Test
{
    public static void main(String[] args)
    {
        final SystemTextTerminal terminal = new SystemTextTerminal();
        final TextIO             textIO   = new TextIO(terminal);

        final String password = textIO.newStringInputReader()
            .withMinLength(1)
            .withInputMasking(true)
            .read("Password");
    }
}

Result:

textio-input-masking

Java version:

C:\tmp\textio>java -version
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment Temurin-17.0.1+12 (build 17.0.1+12)
OpenJDK 64-Bit Server VM Temurin-17.0.1+12 (build 17.0.1+12, mixed mode, sharing)

Expected result is for the input to be masked and the typed characters to be invisible.

siordache commented 2 years ago

Some terminals are not capable of masking the input. SystemTextTerminal is one of them:

It is not capable to mask input strings, therefore not recommended when reading sensitive data.

RedShift1 commented 2 years ago

Ah ok, I missed that in the docs. Thanks.