Browse Source

[비밀번호 규칙 변경] 1. 의료진관리 -> 의료진 신규 등록 페이지 작업

huiwon.seo 4 years ago
parent
commit
d2e7d37905

+ 32 - 0
src/main/java/com/lemon/lifecenter/common/CommonController.java

@@ -0,0 +1,32 @@
+package com.lemon.lifecenter.common;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+@Controller
+@RequestMapping("/common")
+public class CommonController {
+    
+    @RequestMapping( value="/passwordCheck", method=RequestMethod.POST )
+    @ResponseBody
+    public String passwordCheck( @RequestParam(value="password", required=true) String password ) {
+        
+        /**
+         * 0: OK (규칙에 부합됨)
+         * 1: 입력된 패스워드가 null이거나 없음.
+         * 2: 입력된 패스워드가 16자 이상임 15자리까지 입력가능.
+         * 3: 입력된 패스워드가 2조합 미만이고 10자리 미만.
+         * 4: 입력된 패스워드가 2조합인데, 8자리 미만임. 
+         * 5: 
+         * 6: 입력된 패스워드가 3자리 이상 연속된 값이 포함됨. (예, abc, def, 123)
+         * 7: 입력된 패스워드가 키보드 조합으로 3자리 이상 연속된 값이 포함됨. (예, asd, qwe, jkl)
+         * 8: 입력된 패스워드가 3자리 이상 같은 값이 포함됨. (예, aaa, 222)
+         * 99: 에러
+         */
+        
+        return LifeCenterFunction.checkPw( password );
+    }
+}

+ 92 - 0
src/main/java/com/lemon/lifecenter/common/LifeCenterFunction.java

@@ -29,6 +29,8 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Random;
 import java.util.UUID;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.crypto.Cipher;
 import javax.crypto.Mac;
@@ -639,4 +641,94 @@ public class LifeCenterFunction {
         
         return strSymptom;
     }
+    
+    
+    /**
+     * 패스워드를 규칙에 맞게 체크한다.
+     * [사용방법]
+     * LifeCenterFunction.checkPw(String inputPw);
+     * Return
+     * 0: OK (규칙에 부합됨)
+     * 1: 입력된 패스워드가 null이거나 없음.
+     * 2: 입력된 패스워드가 16자 이상임 15자리까지 입력가능.
+     * 3: 입력된 패스워드가 2조합 미만이고 10자리 미만.
+     * 4: 입력된 패스워드가 2조합인데, 8자리 미만임. 
+     * 5: 
+     * 6: 입력된 패스워드가 3자리 이상 연속된 값이 포함됨. (예, abc, def, 123)
+     * 7: 입력된 패스워드가 키보드 조합으로 3자리 이상 연속된 값이 포함됨. (예, asd, qwe, jkl)
+     * 8: 입력된 패스워드가 3자리 이상 같은 값이 포함됨. (예, aaa, 222)
+     * 99: 에러
+     */
+    public static String checkPw(String inputPw) {
+        String strResult = "";
+        
+        if( inputPw == null || inputPw.equals("") ) return "1";
+        if( inputPw.length() > 15 ) return "2";
+ 
+        try {
+            Pattern pAlphabetLow = null;
+            Pattern pAlphabetUp  = null;
+            Pattern pNumber      = null;
+            Pattern pSpecialChar = null;
+            Pattern pThreeChar   = null;
+            Matcher match;
+            int nCharType = 0;
+ 
+            pAlphabetLow = Pattern.compile("[a-z]");             // 영소문자
+            pAlphabetUp = Pattern.compile("[A-Z]");             // 영대문자
+            pNumber = Pattern.compile("[0-9]");                     // 숫자
+            pSpecialChar = Pattern.compile("\\p{Punct}");         // 특수문자 -_=+\\|()*&^%$#@!~`?></;,.:'
+            pThreeChar = Pattern.compile("(\\p{Alnum})\\1{2,}");// 3자리 이상 같은 문자 또는 숫자
+ 
+            // 영소문자가 포함되어 있는가?
+            match = pAlphabetLow.matcher(inputPw);
+            if(match.find()) nCharType++;
+            // 영대문자가 포함되어 있는가?
+            match = pAlphabetUp.matcher(inputPw);
+            if(match.find()) nCharType++;
+            // 숫자가 포함되어 있는가?
+            match = pNumber.matcher(inputPw);
+            if(match.find()) nCharType++;
+            // 특수문자가 포함되어 있는가?
+            match = pSpecialChar.matcher(inputPw);
+            if(match.find()) nCharType++;
+            
+            // 3자리 이상 같은 문자 또는 숫자가 포함되어 있는가?
+            match = pThreeChar.matcher(inputPw);
+            if(match.find()) return "8"; //입력된 패스워드가 3자리 이상 같은 값이 포함됨. (예, aaa, 222)
+            
+            // 2가지 이상 조합인가?
+            if(nCharType >= 2) {
+                // 8자리 미만인경우 
+                if(inputPw.length() < 8) return "4";
+                else strResult = "0";
+            } else {
+                //10자리 미만인 경우
+                if(inputPw.length() < 10) return "3";
+                else strResult = "0";
+            }
+ 
+            // 연속된 3자리 이상의 문자나 숫자가 포함되어 있는가?
+            String listThreeChar = "abc|bcd|cde|def|efg|fgh|ghi|hij|ijk|jkl|klm|lmn|mno|nop|opq|qrs|rst|stu|tuv|uvw|vwx|wxy|xyz|012|123|234|345|456|567|678|789|890";
+            String[] arrThreeChar = listThreeChar.split("\\|");
+            for (int i=0; i<arrThreeChar.length; i++) {
+                if(inputPw.toLowerCase().matches(".*" + arrThreeChar[i] + ".*")) {
+                    return "6";
+                }
+            }
+ 
+            // 연속된 3자리 이상의 키보드 문자가 포함되어 있는가?
+            String listKeyboardThreeChar = "qwe|wer|ert|rty|tyu|yui|uio|iop|asd|sdf|dfg|fgh|ghj|hjk|jkl|zxc|xcv|cvb|vbn|bnm";
+            String[] arrKeyboardThreeChar = listKeyboardThreeChar.split("\\|");
+            for (int j=0; j<arrKeyboardThreeChar.length; j++) {
+                if(inputPw.toLowerCase().matches(".*" + arrKeyboardThreeChar[j] + ".*")) {
+                    return "7";
+                }
+            }
+        } catch (Exception ex) {
+            strResult = "99";
+        }
+ 
+        return strResult;
+    }
 }

+ 5 - 0
src/main/java/com/lemon/lifecenter/controller/RoleController.java

@@ -3,6 +3,9 @@ package com.lemon.lifecenter.controller;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.transaction.annotation.Propagation;
@@ -10,9 +13,11 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.servlet.ModelAndView;
 
 import com.lemon.lifecenter.common.LifeCenterController;
+import com.lemon.lifecenter.common.LifeCenterFunction;
 import com.lemon.lifecenter.dto.RoleDTO;
 import com.lemon.lifecenter.service.RoleService;
 

+ 6 - 6
src/main/webapp/WEB-INF/jsp/staff/new.jsp

@@ -30,9 +30,9 @@ $( function(){
                 phoneValid : true
             },
             password : {
-                minlength : 8,
-                maxlength : 15,
-                passwordValid : true,
+//                 minlength : 8,
+//                 maxlength : 15,
+                passwordCheck : true
             },
             passwordConfirm : {
                 equalTo: "#password",
@@ -43,8 +43,8 @@ $( function(){
                 remote : "이미 존재하는 아이디입니다"
             },
             password : {
-                minlength : "비밀번호를 확인하세요 (영문, 숫자, 특수문자를 혼합하여 8 ~ 15자 이내)",
-                maxlength : "비밀번호를 확인하세요 (영문, 숫자, 특수문자를 혼합하여 8 ~ 15자 이내)"
+//                 minlength : "비밀번호를 확인하세요 (영문, 숫자, 특수문자를 혼합하여 8 ~ 15자 이내)",
+//                 maxlength : "비밀번호를 확인하세요 (영문, 숫자, 특수문자를 혼합하여 8 ~ 15자 이내)"
             },
             passwordConfirm : {
                 equalTo: "비밀번호가 일치하지 않습니다.",
@@ -116,7 +116,7 @@ $( function(){
                                             <tr>
                                                 <th><span class="fix">*</span>비밀번호</th>
                                                 <td colspan="3">
-                                                    <input type="password" id="password" class="form-control pass-group" name="password" placeholder="숫자, 영문, 특수문자 조합 8~15자 이내" required>
+                                                    <input type="password" id="password" class="form-control pass-group" name="password" placeholder="10자리 이상의 비밀번호 or 최소 8자리 이상 (영어 대문자, 소문자, 숫자, 특수문자) 2종류 이상의 조합" required>
                                                 </td>
                                             </tr>
                                             <tr>

+ 55 - 0
src/main/webapp/resources/js/common/common.js

@@ -5,6 +5,61 @@ $(function(){
         return this.optional(element) || /^.*(?=.*\d)(?=.*[a-zA-Z])(?=.*[!@#$%^&+=]).*$/.test(value);
     }, "비밀번호를 확인하세요 (영문, 숫자, 특수문자를 혼합하여 8 ~ 15자 이내)" );
     
+    $.validator.addMethod( "passwordCheck",  function( value, element ) {
+        var valid = false;
+        var errorMsg = "10자리 이상의 비밀번호 or 최소 8자리 이상 (영어 대문자, 소문자, 숫자, 특수문자) 2종류 이상의 조합";
+        
+        $.ajax({
+            url      : "/common/passwordCheck",
+            data     : "password=" + value,
+            method   : "POST",
+            dataType : "json",
+            async    : false,
+            success  : function( result ){
+                console.log( result );
+                
+                /**
+                 * 0: OK (규칙에 부합됨)
+                 * 1: 입력된 패스워드가 null이거나 없음.
+                 * 2: 입력된 패스워드가 16자 이상임 15자리까지 입력가능.
+                 * 3: 입력된 패스워드가 2조합 미만이고 10자리 미만.
+                 * 4: 입력된 패스워드가 2조합인데, 8자리 미만임. 
+                 * 5: 
+                 * 6: 입력된 패스워드가 3자리 이상 연속된 값이 포함됨. (예, abc, def, 123)
+                 * 7: 입력된 패스워드가 키보드 조합으로 3자리 이상 연속된 값이 포함됨. (예, asd, qwe, jkl)
+                 * 8: 입력된 패스워드가 3자리 이상 같은 값이 포함됨. (예, aaa, 222)
+                 * 99: 에러
+                 */
+                 
+                if( result == "0" ){
+                    valid = true;
+                    
+                } else if( result == "1" ) {
+                    errorMsg = "패스워드를 입력하세요";
+                } else if( result == "2" ) {
+                    errorMsg = "15자리 이내로 입력하세요";
+                } else if( result == "3" ) {
+                    errorMsg = "10자리 이상의 비밀번호 or 최소 8자리 이상 (영어 대문자, 소문자, 숫자, 특수문자) 2종류 이상의 조합";
+                } else if( result == "4" ) {
+                    errorMsg = "10자리 이상의 비밀번호 or 최소 8자리 이상 (영어 대문자, 소문자, 숫자, 특수문자) 2종류 이상의 조합";
+                } else if( result == "5" ) {
+                
+                } else if( result == "6" ) {
+                    errorMsg = "입력된 패스워드가 3자리 이상 연속된 값이 포함됨.  (예, abc, def, 123)";
+                } else if( result == "7" ) {
+                    errorMsg = "입력된 패스워드가 키보드 조합으로 3자리 이상 연속된 값이 포함됨. (예, asd, qwe, jkl)";
+                } else if( result == "8" ) {
+                    errorMsg = "입력된 패스워드가 3자리 이상 같은 값이 포함됨. (예, aaa, 222)";
+                }
+            }
+        });
+        
+        $.validator.messages["passwordCheck"] = errorMsg;
+        
+        return this.optional(element) || valid; 
+        
+    }, '' );
+    
     $.validator.addMethod( "phoneValid", function( phoneNumber, element ) {
         var tel = /^(01[016789]{1}|02|0[3-9]{1}[0-9]{1})-?[0-9]{3,4}-?[0-9]{4}$/;
         if(this.optional(element) || (tel.test(phoneNumber))){