码迷,mamicode.com
首页 > 其他好文 > 详细

使用正则表达式提高用户密码的复杂度和安全性

时间:2017-01-10 11:37:57      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:pass   main   密码   []   password   字母   duti   regex   length   

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));
    }
    
}

 

使用正则表达式提高用户密码的复杂度和安全性

标签:pass   main   密码   []   password   字母   duti   regex   length   

原文地址:http://www.cnblogs.com/fuyuanming/p/6268512.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!