Rules to validate password

	static function check_pw($pw){
		if(strlen($pw) < 6){
			self::$err = '密碼至少要6個字元';
			return false;
		}

		//Has numbers
		$pattern = '/\d+/';
		preg_match($pattern, $pw, $result);
		//logg($result);
		if($result == false){
			self::$err = '密碼必須含有數字';
			return false;
		}

		//Has alphabet
		$pattern = '/[a-zA-Z]+/';
		preg_match($pattern, $pw, $result);
		//logg($result);
		if($result == false){
			self::$err = '密碼必須含有英文字母';
			return false;
		}

		//Check repeated characters for 4 times
		$pattern = '/([a-zA-Z0-9])\1{3,}/';
		preg_match($pattern, $pw, $result);
		//logg($result);
		if($result != false){
			self::$err = '密碼不可以有重複的4個以上字元';
			return false;
		}

		//Check repeated characters
		$result = self::has_continuous_numbers($pw);
		//logg($result);
		if($result == true){
			self::$err = '密碼不可以含有連續的4位數字';
			return false;
		}

		return true;
	}

	static function has_continuous_numbers($v){
		$pattern = '/\d{4,}/';
		preg_match_all($pattern, $v, $result);

		if(isset($result) == false || $result == false){
			return false;
		}
		//logg($result);

		foreach ($result[0] as $key => $value) {
			for($i = 0; $i <= strlen($value) - 4; $i++){
				$current = -1;
				$start = $i;
				$gap = 0;
				$check_result = true;

				for($j = 0; $j < 4; $j++){
					$c = substr($value, $start, 1);

					if($j == 0){
						$current = $c;
						$start++;
						continue;
					}

					if($j == 1){
						$gap = $c - $current;
					}

					if($c - $current != $gap){
						$check_result = false;
						break;
					}

					$current = $c;
					$start++;
				}

				if($check_result == true){
					return true;
				}
			}
		}

		return false;
	}