如何在java中登录时检查文件名和密码是否正确

时间:2017-03-12 07:33:27

标签: java passwords

我想检查文件名和密码文件是否正确继续代码..否则检查密码文件会出错。

我的代码是:

Scanner scanInputUser = new Scanner(System.in);
        System.out.println("Please Enter UserName:");
        String fileName = scanInputUser.nextLine();

 fileHandler.setUserName(fileName); // This file name has already been defined in another class.
//and using this method with instance class..


        try {
            System.out.println("Please Enter Password:");
            String passSaver = scanInputUser.nextLine();
            cryptography.setKeyUser(passSaver); // password decrypt save to same file. 
//This method has already been defined in another class.

            fileHandler.passwordSaver(passSaver); 

        } catch (Exception e) {
            e.printStackTrace();
        }

//TODO check correct password for file name
(note: password file name saved to the same file).

1 个答案:

答案 0 :(得分:-1)

您可能正在寻找equals(Object o)Oracle Doc),但我无法确定您对此问题的描述。

简短的例子:

if (passSaver.equals(passPhrase)) {
    dostuff();
}

另见: How do I compare strings in Java?