All pastes #22779 Raw Edit

Skudd

public php v1 · immutable
#22779 ·published 2005-09-13 03:45 UTC
rendered paste body
	function ValidateRegister(&$errors) {		global $config;				if(!isset($config['registration']['min_chars'])) $config['registration']['min_chars'] = 4;		if(!isset($config['registration']['max_chars'])) $config['registration']['max_chars'] = 15;				$output = true;			// First, let's make sure $_POST isn't empty...		if(sizeof($_POST) == 0) {			$errors['form'] = 'Empty form submitted.';			$output = false;		}				// Let's look for invalid characters in the login				$chars = (bool)preg_match('/[^\w\d]+/', trim($_POST['user_login']));		if($chars == true) {			$errors['user_login'][] = 'Login may only be alphanumeric (a-z, A-Z, 0-9).';			$output = false;		}						// Okay, now let's make sure the login name meets the requirements...		$len = strlen($_POST['user_login']);		if(!($len >= $config['registration']['min_chars'] && $len <= $config['registration']['max_chars'])) {			$errors['user_login'][] = 'Login must be between '.$config['registration']['min_chars'].' and '.$config['registration']['max_chars'].' characters in length.';			$output = false;		}				// ...and isn't in use already		$user = GetUserByLogin(SafeStr($_POST['user_login']));		if($user != false) {			$errors['user_login'][] = 'Login already in use.';			$output = false;		}				// What about the e-mail address?		$valid = preg_match('/[\w\d-_.]+\@[\w\d]+([.]{1}|[\w\d-_]+)\w+/', $_POST['user_email']);		if(empty($valid)) {			$errors['user_email'] = 'Invalid e-mail address.';			$output = false;		}				// Let the user know that their name is being truncated...		if(strlen($_POST['user_name']) > 255) {			$_POST['user_name'] = substr($_POST['user_name'], 0, 255);			$errors['user_name'][] = 'Your name was too long for the database and has been truncated to 255 characters.';			$output = false;		}				// Did they supply a password?		$len = strlen($_POST['user_password']);		if($len < 4) {			$errors['user_password'][] = 'A password must be supplied and must be at least 4 characters long.';			$output = false;		}				if($output == false) {			$errors['user_password'][] = 'Please re-enter your password.';		}				return $output;	}