无法调用String.equals(Object)


private void login() throws UserException, NoSuchAlgorithmException, InvalidKeySpecException {
System.out.println("=== Log in ===");
while (true) {
System.out.println("Enter your login nor Enter EXIT for return to main menu ->");
String inputLogin = this.sc.nextLine();
if ("EXIT".equalsIgnoreCase(inputLogin)) {
break;
}
try {
User user = userImpl.read(inputLogin);
if (user.getLogin() == null) {
System.err.println("Username incorrect.");
} else {
System.out.println("Enter your password n or Enter EXIT for return to main menu ->");
String inputPassword = this.sc.nextLine();
user = userImpl.readPassword(inputPassword);
if (!user.getPassword().equals(generateStrongPasswordHash(inputPassword)) || "EXIT".equalsIgnoreCase(inputPassword)) {
System.err.println("Password incorrect");
continue;
}
System.out.println("Log in successfully✔✔✔");
}
} catch (UserException | NoSuchAlgorithmException | InvalidKeySpecException e) {
e.printStackTrace();
}
}
}

我正在尝试使用JDBC(MySQL(实现一个控制台程序Cinema。在使用登录方法后,我得到了这个异常。我如何在控制台应用程序上实现授权?使用者用户

看起来user.getPassword()正在返回null。因此,我建议您在检查user.getPassword().equals(generateStrongPasswordHash(inputPassword))之前先检查user.getPassword() === null

private void login() throws UserException, NoSuchAlgorithmException, InvalidKeySpecException {
System.out.println("=== Log in ===");
while (true) {
System.out.println("Enter your login nor Enter EXIT for return to main menu ->");
String inputLogin = this.sc.nextLine();
if ("EXIT".equalsIgnoreCase(inputLogin)) {
break;
}
try {
User user = userImpl.read(inputLogin);
if (user.getLogin() == null) {
System.err.println("Username incorrect.");
} else {
System.out.println("Enter your password n or Enter EXIT for return to main menu ->");
String inputPassword = this.sc.nextLine();
user = userImpl.readPassword(inputPassword);
if (user.getPassword() === null || !user.getPassword().equals(generateStrongPasswordHash(inputPassword)) || "EXIT".equalsIgnoreCase(inputPassword)) {
System.err.println("Password incorrect");
continue;
}
System.out.println("Log in successfully✔✔✔");
}
} catch (UserException | NoSuchAlgorithmException | InvalidKeySpecException e) {
e.printStackTrace();
}
}
}

相关内容

  • 没有找到相关文章

最新更新