<?php
/**
* 用户注册函数库
* @author moufer<moufer@163.com>
* @copyright (C)2001-2007 Moufersoft
* @version $Id: fun_reg.php 3 2007-10-1 $
*/

!defined('IN_MUDDER') && exit('Access Denied');

function validateEmail($string){
    return !$string ? -1 : (!string_length($string, 2, 80) ? 1 : (!isemail($string) ? 2 : 0));
}

function validateusername($string) {
    global $_config; //utf-8中一个中文汉字的算3个字符
	if(strlen($string) > 15) return 1;
	if(!$string) return -1;
    $guestexp = '\xA1\xA1|\xAC\xA3|^Guest|^\xD3\xCE\xBF\xCD|\xB9\x43\xAB\xC8';
    if(preg_match("/^\s*$|^c:\\con\\con$|[%,\*\"\s\t\<\>\&]|$guestexp/is", $string)) return 2;
    $censorwords = $_config['censoruser'] ? explode("\r\n", $_config['censoruser']) : '';
    if($censorwords) foreach($censorwords as $censor) {
        $preg = "/".str_replace("*", ".*?", $censor)."/is";
        if(preg_match($preg, $string)) return 3;
    }
    return 0;
}

function validatePassword($string){
    return !$string ? -1 : (!string_length($string, 6, 20) ? 1 : (!preg_match("/[a-zA-Z0-9_~!@#]+/i", $string) ? 2 : 0));
}
?>
