简体   繁体   English

从Java创建的可执行文件中的屏蔽密码

[英]Masking password in executable created from java

I've written a small java program that required user input for login, to do other stuff. 我编写了一个小的Java程序,需要用户输入登录才能执行其他操作。 Executing the .jar file of my program masks the password as expected. 执行我的程序的.jar文件会按预期屏蔽密码。

However, when I create a .exe from the same .jar and run it, the application doesn't mask the password. 但是,当我从相同的.jar创建一个.exe并运行它时,该应用程序不会屏蔽密码。 What should I do to make the .exe mask the password? 我应该怎么做才能使.exe屏蔽密码?

Console cons = System.console();
        if (cons == null) {
            System.err.println("No console.");
            System.exit(1);
        }
        String username = cons.readLine("Enter username: ");
        char[] passwd = cons.readPassword("Enter Password: ");
        String password = new String(passwd);

I'm using Console.readPassword to mask the password and I used lanuch4j to create my .exe 我正在使用Console.readPassword掩盖密码,并使用lanuch4j创建了我的.exe

Even if it is a command line only application, it may be possible for you to show a dialog popup just for user credentials, as discussed here . 即使它是一个命令行唯一的应用程序,有可能让你只显示一个对话框弹出用户凭据,如讨论在这里 The only case this would not work is if GUI is not available (remote text-only session or some server without GUI installed). 唯一无法使用的情况是GUI不可用(远程纯文本会话或未安装GUI的某些服务器)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM