자바
패스워드 체크(자바 <->스크립트)
kvoy
2007. 7. 19. 20:08
================ 아래 스크립트 ========================
var cnt = 0, cnt2 = 1, cnt3 = 1, cnt4 = 1;
var temp = "";
for(i=0;i < p_id.length;i++){
temp_id = p_id.charAt(i);
for(j=0;j < p_pass.length;j++){
if (cnt > 0){
j = tmp_pass_no + 1;
}
if (temp == "r"){
j=0;
temp="";
}
temp_pass = p_pass.charAt(j);
if(temp_id == temp_pass){
cnt = cnt + 1;
tmp_pass_no = j;
break;
}else if(cnt > 0 && j > 0){
temp = "r";
cnt = 0;
}else{
cnt = 0;
}
}
if (cnt > 3) break;
}
if (cnt > 3){
alert("변경 PASSWORD가 ID와 4자 이상 중복되거나,\n\n연속된 글이나 순차적인 숫자를 4개이상 사용해서는 안됩니다.");
form1.new_password.value ="";
form1.new_password2.value ="";
form1.new_password.focus();
return ;
}
for(i=0;i < p_pass.length;i++){
temp_pass1 = p_pass.charAt(i);
next_pass = (parseInt(temp_pass1.charCodeAt(0)))+1;
next_pass3 = (parseInt(temp_pass1.charCodeAt(0)))-1;
temp_p = p_pass.charAt(i+1);
temp_pass2 = (parseInt(temp_p.charCodeAt(0)));
if (temp_pass2 == next_pass)
cnt2 = cnt2 + 1;
else
cnt2 = 1;
if(temp_pass2 == next_pass3)
cnt4 = cnt4 +1;
else
cnt4 = 1;
if (temp_pass1 == temp_p)
cnt3 = cnt3 + 1;
else
cnt3 = 1;
if (cnt2 > 3) break;
if (cnt3 > 3) break;
if (cnt4 > 3) break;
}
if (cnt2 > 3){
alert("변경 PASSWORD에 연속된 글이나 순차적인 숫자를 4개이상 사용해서는 안됩니다.");
form1.new_password.value ="";
form1.new_password2.value ="";
form1.new_password.focus();
return ;
}
if (cnt4 > 3){
alert("변경 PASSWORD에 연속된 글이나 순차적인 숫자를 4개이상 사용해서는 안됩니다.");
form1.new_password.value ="";
form1.new_password2.value ="";
form1.new_password.focus();
return ;
}
if (cnt3 > 3){
alert("변경 PASSWORD에 반복된 문자/숫자를 4개이상 사용해서는 안됩니다.");
form1.new_password.value ="";
form1.new_password2.value ="";
form1.new_password.focus();
return ;
}
========================================== 아래 자바 =========================================================
// 숫자로만 되어 있을 경우 (영문으로만 되어 있을 경우는 로그인 가능)
if( !pass_num_check(d_new_password))
{
request.setAttribute(LGWebKeys.ErrorMsg, "숫자로만 되어 있을 경우");
request.setAttribute(LGWebKeys.ErrorMode, "end");
return errorPage;
}
// 아이디와 패스워드가 4자리 이상 중복될 경우
if (id_pass_check(sid, d_new_password) > 3)
{
request.setAttribute(LGWebKeys.ErrorMsg, "아이디와 패스워드가 4자리 이상 중복될 경우");
request.setAttribute(LGWebKeys.ErrorMode, "end");
return errorPage;
}
// 패스워드 구성이 연속된 숫자나 영문으로 4개 이상일 경우
if (!passwd_count(d_new_password))
{
request.setAttribute(LGWebKeys.ErrorMsg, "패스워드 구성이 연속된 숫자나 영문으로 4개 이상일 경우");
request.setAttribute(LGWebKeys.ErrorMode, "end");
return errorPage;
}
// 아이디와 패스워드가 4자리이상 중복될 경우
private int id_pass_check(String member_id, String passwd)
{
int count = 0, count2 = 1, count3 = 1, tmp_pass_no = 0, i = 0, j = 0;
char temp = '\u0000';
char temp_id = '\u0000';
char temp_pass = '\u0000';
for( i = 0 ; i < member_id.length() ; i++ ) {
temp_id = member_id.charAt(i);
for( j = 0 ; j < passwd.length() ; j++ ) {
if(count > 0) {
j = tmp_pass_no + 1;
}
if(temp == 'r') {
j=0;
temp='\u0000'; // temp를 null문자로 초기화 한다.
}
if( j == passwd.length() ) {
break;
} else {
temp_pass = Character.toLowerCase(passwd.charAt(j)); // passwd의 소문자화한뒤 비교
}
if(temp_id == temp_pass) {
count = count + 1;
tmp_pass_no = j;
break;
} else if(count > 0 && j > 0) {
temp= 'r';
count = 0;
} else {
count = 0;
}
}
if (count > 3) {
break;
}
}
return count;
}
// 패스워드가 숫자로만 되어있는지 체크
private boolean pass_num_check(String passwd)
{
int k = 0, pass_num_check_count=0;
for( k = 0 ; k < passwd.length() ; k++ ) {
if(passwd.charAt(k) >= '0' && passwd.charAt(k) <= '9' ) {
pass_num_check_count = pass_num_check_count +1;
}
}
if( passwd.length() == pass_num_check_count ) {
return false;
} else {
return true;
}
}
// 패스워드 구성이 연속된 숫자나 영문으로 4개 이상인지 체크
private boolean passwd_count(String passwd)
{
int x = 0, count2 = 1, count3 = 1;
for( x = 0 ; x < passwd.length() ; x++) {
char temp_p = '\u0000';
char temp_pass1 = '\u0000';
char temp_c = '\u0000';
temp_pass1 = passwd.charAt(x);// 입력받은 비밀번호의 char값
if((x+1) == passwd.length()) {
break;
} else {
temp_p = passwd.charAt(x+1);// 입력받은 비밀번호의 현재 index의 다음 index char값(index+1)
temp_c = (char)(temp_pass1+1);// 입력받은 char값의 다음 char값 ( ex. a 다음은 b, 1 다음은 2...)
}
if(temp_c == temp_p) {// 입력받은 char값의 다음 index char값과 다음 char값을 비교
count3 = count3 + 1;
} else {
count3 = 1;
}
if (count3 > 3) {
break;
}
}
if(count3 > 3) {
return false;
} else {
return true;
}
}
var cnt = 0, cnt2 = 1, cnt3 = 1, cnt4 = 1;
var temp = "";
for(i=0;i < p_id.length;i++){
temp_id = p_id.charAt(i);
for(j=0;j < p_pass.length;j++){
if (cnt > 0){
j = tmp_pass_no + 1;
}
if (temp == "r"){
j=0;
temp="";
}
temp_pass = p_pass.charAt(j);
if(temp_id == temp_pass){
cnt = cnt + 1;
tmp_pass_no = j;
break;
}else if(cnt > 0 && j > 0){
temp = "r";
cnt = 0;
}else{
cnt = 0;
}
}
if (cnt > 3) break;
}
if (cnt > 3){
alert("변경 PASSWORD가 ID와 4자 이상 중복되거나,\n\n연속된 글이나 순차적인 숫자를 4개이상 사용해서는 안됩니다.");
form1.new_password.value ="";
form1.new_password2.value ="";
form1.new_password.focus();
return ;
}
for(i=0;i < p_pass.length;i++){
temp_pass1 = p_pass.charAt(i);
next_pass = (parseInt(temp_pass1.charCodeAt(0)))+1;
next_pass3 = (parseInt(temp_pass1.charCodeAt(0)))-1;
temp_p = p_pass.charAt(i+1);
temp_pass2 = (parseInt(temp_p.charCodeAt(0)));
if (temp_pass2 == next_pass)
cnt2 = cnt2 + 1;
else
cnt2 = 1;
if(temp_pass2 == next_pass3)
cnt4 = cnt4 +1;
else
cnt4 = 1;
if (temp_pass1 == temp_p)
cnt3 = cnt3 + 1;
else
cnt3 = 1;
if (cnt2 > 3) break;
if (cnt3 > 3) break;
if (cnt4 > 3) break;
}
if (cnt2 > 3){
alert("변경 PASSWORD에 연속된 글이나 순차적인 숫자를 4개이상 사용해서는 안됩니다.");
form1.new_password.value ="";
form1.new_password2.value ="";
form1.new_password.focus();
return ;
}
if (cnt4 > 3){
alert("변경 PASSWORD에 연속된 글이나 순차적인 숫자를 4개이상 사용해서는 안됩니다.");
form1.new_password.value ="";
form1.new_password2.value ="";
form1.new_password.focus();
return ;
}
if (cnt3 > 3){
alert("변경 PASSWORD에 반복된 문자/숫자를 4개이상 사용해서는 안됩니다.");
form1.new_password.value ="";
form1.new_password2.value ="";
form1.new_password.focus();
return ;
}
========================================== 아래 자바 =========================================================
// 숫자로만 되어 있을 경우 (영문으로만 되어 있을 경우는 로그인 가능)
if( !pass_num_check(d_new_password))
{
request.setAttribute(LGWebKeys.ErrorMsg, "숫자로만 되어 있을 경우");
request.setAttribute(LGWebKeys.ErrorMode, "end");
return errorPage;
}
// 아이디와 패스워드가 4자리 이상 중복될 경우
if (id_pass_check(sid, d_new_password) > 3)
{
request.setAttribute(LGWebKeys.ErrorMsg, "아이디와 패스워드가 4자리 이상 중복될 경우");
request.setAttribute(LGWebKeys.ErrorMode, "end");
return errorPage;
}
// 패스워드 구성이 연속된 숫자나 영문으로 4개 이상일 경우
if (!passwd_count(d_new_password))
{
request.setAttribute(LGWebKeys.ErrorMsg, "패스워드 구성이 연속된 숫자나 영문으로 4개 이상일 경우");
request.setAttribute(LGWebKeys.ErrorMode, "end");
return errorPage;
}
// 아이디와 패스워드가 4자리이상 중복될 경우
private int id_pass_check(String member_id, String passwd)
{
int count = 0, count2 = 1, count3 = 1, tmp_pass_no = 0, i = 0, j = 0;
char temp = '\u0000';
char temp_id = '\u0000';
char temp_pass = '\u0000';
for( i = 0 ; i < member_id.length() ; i++ ) {
temp_id = member_id.charAt(i);
for( j = 0 ; j < passwd.length() ; j++ ) {
if(count > 0) {
j = tmp_pass_no + 1;
}
if(temp == 'r') {
j=0;
temp='\u0000'; // temp를 null문자로 초기화 한다.
}
if( j == passwd.length() ) {
break;
} else {
temp_pass = Character.toLowerCase(passwd.charAt(j)); // passwd의 소문자화한뒤 비교
}
if(temp_id == temp_pass) {
count = count + 1;
tmp_pass_no = j;
break;
} else if(count > 0 && j > 0) {
temp= 'r';
count = 0;
} else {
count = 0;
}
}
if (count > 3) {
break;
}
}
return count;
}
// 패스워드가 숫자로만 되어있는지 체크
private boolean pass_num_check(String passwd)
{
int k = 0, pass_num_check_count=0;
for( k = 0 ; k < passwd.length() ; k++ ) {
if(passwd.charAt(k) >= '0' && passwd.charAt(k) <= '9' ) {
pass_num_check_count = pass_num_check_count +1;
}
}
if( passwd.length() == pass_num_check_count ) {
return false;
} else {
return true;
}
}
// 패스워드 구성이 연속된 숫자나 영문으로 4개 이상인지 체크
private boolean passwd_count(String passwd)
{
int x = 0, count2 = 1, count3 = 1;
for( x = 0 ; x < passwd.length() ; x++) {
char temp_p = '\u0000';
char temp_pass1 = '\u0000';
char temp_c = '\u0000';
temp_pass1 = passwd.charAt(x);// 입력받은 비밀번호의 char값
if((x+1) == passwd.length()) {
break;
} else {
temp_p = passwd.charAt(x+1);// 입력받은 비밀번호의 현재 index의 다음 index char값(index+1)
temp_c = (char)(temp_pass1+1);// 입력받은 char값의 다음 char값 ( ex. a 다음은 b, 1 다음은 2...)
}
if(temp_c == temp_p) {// 입력받은 char값의 다음 index char값과 다음 char값을 비교
count3 = count3 + 1;
} else {
count3 = 1;
}
if (count3 > 3) {
break;
}
}
if(count3 > 3) {
return false;
} else {
return true;
}
}