模擬簡單登錄模塊:預設用戶名 u539f、密碼 u539fpassword,通過控制台輸入驗證。
import java.util.Scanner;
public class CheckLogin {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("請輸入登錄用戶名:");
String username = scan.nextLine();
System.out.print("請輸入登錄密碼:");
String password = scan.nextLine();
if (!username.equals("u539f")) {
System.out.println("用戶名非法。");
} else if (!password.equals("u539fpassword")) {
System.out.println("登陸密碼錯誤。");
} else {
System.out.println("恭喜您,登錄信息通過驗證。");
}
scan.close();
}
}
Objects.equals() 避免空指針Spring Security、Apache Shiro 提供開箱即用的認證授權體系,支持多種 Realm(JDBC、LDAP、OAuth2 等)。