私が書いたパスワード強度検証方法(オリジナル)



/*
 *  :
 *                ,       ,            
 *  :
 *  pwd   ,     
 *  obj          ,   jquery     
 *  minLen       
 *  maxLen       
 */
function showPassstrength(pwd, obj, minLen, maxLen) {
	var dictionary = [];

	var containsAToZ = function(str) {
		var aToZ = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
				"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w",
				"x", "y", "z" ];
		var r = false;
		for ( var i = 0; i < aToZ.length; i++) {
			if (str.indexOf(aToZ[i]) >= 0) {
				r = true;
				break;
			}
		}
		return r;
	}

	var containsNumber = function(str) {
		var numbers = [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ];
		var r = false;
		for ( var i = 0; i < numbers.length; i++) {
			if (str.indexOf(numbers[i]) >= 0) {
				r = true;
				break;
			}
		}
		return r;
	}

	var contains_ = function(str) {
		return str.indexOf("_") >= 0 ? true : false;
	}

	var isANumberSequence = function(str) {
		var array = str.split("");
		var eq = true;
		var num = parseInt(array[1]);
		var diff = num - parseInt(array[0])
		for ( var i = 2; i < array.length; i++) {
			if (parseInt(array[i]) != num + diff) {
				eq = false;
				break;
			}
			num = array[i];
		}
		return eq;
	}

	var reverse = function(str) {
		return str.split("").reverse().join("");
	}

	pwd = pwd.toLowerCase();
	var level = 1;
	/** ****************    ***************** */
	if (containsAToZ(pwd)) {
		level++;
	}
	if (containsNumber(pwd)) {
		level++;
	}
	if (contains_(pwd)) {
		level++;
	}
	if ((containsAToZ(pwd) && containsNumber(pwd))
			|| (containsAToZ(pwd) && contains_(pwd))
			|| (containsNumber(pwd) && contains_(pwd))) {
		level++;
	}
	if (containsAToZ(pwd) && containsNumber(pwd) && contains_(pwd)) {
		level++;
	}
	/** ****************    ***************** */
	if (pwd.length < (minLen + maxLen) / 2 && pwd.length >= minLen) {
		level--;
	}
	var pwdArray = pwd.split("");
	//                 
	var allEquals = true;
	var element = pwdArray[0];
	for ( var i = 1; i < pwdArray.length; i++) {
		if (pwdArray[i] != element) {
			allEquals = false;
			break;
		}
		element = pwdArray[i];
	}
	if (allEquals)
		level = 0;
	//                  
	if (/^[0-9]+$/.test(pwd)
			&& (isANumberSequence(pwd) || isANumberSequence(reverse(pwd)))) {
		level--;
	}
	//           ,  :abcdefg
	if ("abcdefghijklmnopqrstuvwxyz".indexOf(pwd) > 0) {
		level--;
	}
	//                        ,  :qwertyu
	if ("qwertyuiop".indexOf(pwd) > 0 || "asdfghjkl".indexOf(pwd) > 0
			|| "zxcvbnm".indexOf(pwd) > 0) {
		level--;
	}
	//    2       ,  :567567
	if (pwd.length % 2 == 0) {
		var part1 = pwd.substring(0, pwd.length / 2);
		var part2 = pwd.substring(pwd.length / 2);
		if (part1 == part2)
			level--;
	}
	//    3       ,  :121212
	if (pwd.length % 3 == 0) {
		var part1 = pwd.substring(0, pwd.length / 3);
		var part2 = pwd.substring(pwd.length / 3, pwd.length / 3 * 2);
		var part3 = pwd.substring(pwd.length / 3 * 2);
		if (part1 == part2 && part2 == part3)
			level--;
	}
	//        ,  :19870723
	if (/^[0-9]+$/.test(pwd)) {
		if (pwd.length == 8) {
			var year = parseInt(pwd.substring(0, 4));
			var month = parseInt(pwd.substring(4, 6));
			var day = parseInt(pwd.substring(5, 7));
			if (year >= 1000 && year < 2100 && month >= 1 && month <= 12
					&& day >= 1 && day <= 31) {
				level--;
			}
		}
	}
	//          
	for ( var i = 0; i < dictionary.length; i++) {
		if (pwd == dictionary[i] || dictionary[i].indexOf(pwd) >= 0) {
			level--;
			break;
		}
	}

	if (level < 0)
		level = 0;
	if (level > 5)
		level = 5;
	var levelNames = [ "  ", "  ", "  ", "  ", "  ", "  " ];
	obj.html(levelNames[level]);
}