使用正則表達式提高用戶密碼的復雜度和安全性


public class PassWordUtil {
    
    static String regex_number = "[\\p{Digit}]+";// 數字  
    static String regex_lower = "[\\p{Lower}]+";// 正則表達式 密碼:小寫字母  
    static String regex_upper = "[\\p{Upper}]+";// 大寫字母  
    static String regex_char = "[\\p{Punct}]+";// 標點符號  
    
    public static boolean matchesPass(String user_password){
        if(user_password==null){
            return false;
        }
        
        if(user_password.length()<8){
            return false;
        }
        
        if (user_password.matches(regex_number)  
                || user_password.matches(regex_upper)  
                || user_password.matches(regex_lower)  
                || user_password.matches(regex_char)) {  
            //return "注冊失敗,密碼不符合要求,大寫+小寫+數字+字符(至少包含2種)";  
            return false;
        }  
        return true;
    }
    
    public static void main(String[] args) {
        String a="!!addd";
        System.out.println(matchesPass(a));
    }
    
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM