本文整理汇总了PHP中validate_username函数的典型用法代码示例。如果您正苦于以下问题:PHP validate_username函数的具体用法?PHP validate_username怎么用?PHP validate_username使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了validate_username函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: phpBBRegister
private function phpBBRegister($userObj)
{
$save_sytem_config = $GLOBALS['config'];
global $phpbb_root_path;
global $phpEx;
$messages = array();
$phpbb_root_path = $this->_phpbb_src;
$phpEx = 'php';
ob_start();
if (is_readable($this->_phpbb_src . 'config.php') and is_executable($this->_phpbb_src . 'config.php') and is_readable($this->_phpbb_src . 'common.php') and is_executable($this->_phpbb_src . 'common.php') and is_readable($this->_phpbb_src . 'includes/functions_user.php') and is_executable($this->_phpbb_src . 'includes/functions_user.php')) {
require_once $this->_phpbb_src . 'config.php';
require_once $this->_phpbb_src . 'common.php';
require_once $this->_phpbb_src . 'includes/functions_user.php';
} else {
$messages[] = $this->lang('noaccessphpbbfiles.session.error');
$messages[] = $this->_phpbb_src . 'config.php<br/>' . $this->_phpbb_src . 'common.php<br/>' . $this->_phpbb_src . 'includes/functions_user.php<br/>';
return $messages;
}
if (!validate_username($userObj->u_login)) {
$user_row = array('username' => $userObj->u_login, 'user_password' => phpbb_hash($userObj->u_pass), 'user_email' => $userObj->u_email, 'group_id' => 7, 'user_timezone' => 0.0, 'user_dst' => 0, 'user_lang' => 'ru', 'user_type' => 0, 'user_actkey' => '', 'user_dateformat' => '|d M Y|, H:i', 'user_style' => 1, 'user_regdate' => time());
$lid = user_add($user_row);
if (!$lid) {
$messages[] = $this->lang('cannotadduser.session.error');
}
} else {
$messages[] = $this->lang('loginallreadyexists.session.error');
}
ob_end_clean();
$GLOBALS['config'] = $save_sytem_config;
if (count($messages)) {
return $messages;
} else {
return false;
}
}
示例2: userCheck
function userCheck($username, $user_email)
{
global $user_prefix, $db, $DeniedUserNames, $CensorList;
try {
validate_username($username);
} catch (Exception $e) {
cpg_error($e);
}
$email = Security::check_email($user_email);
if ($email == 0) {
cpg_error('Email address to short');
}
if ($email == -1) {
cpg_error(sprintf(_ERROR_BAD_FORMAT, 'email'));
}
if ($email == -2) {
cpg_error('The email address domain "' . $user_email[1] . '" is disallowed for registration.');
}
if ($db->sql_count($user_prefix . '_users', "user_email='{$user_email}'") > 0 || $db->sql_count($user_prefix . '_users_temp', "user_email='{$user_email}'") > 0) {
cpg_error(_EMAILREGISTERED);
}
/* Now check deleted PHP-Nuke account emails */
if ($db->sql_count($user_prefix . '_users', "user_email='" . md5($user_email) . "'") > 0) {
cpg_error(_EMAILNOTUSABLE);
}
return;
}
示例3: login_submit
/**
* Processes credentials to pass into wp_signon to log a user into WordPress.
*
* @uses check_ajax_referer()
* @uses wp_signon()
* @uses is_wp_error()
*
* @param $user_login (string) Defaults to $_POST['user_login']
* @param $password (string)
* @param $is_ajax (bool) Process as an AJAX request
* @package AJAX
*
* @return userlogin on success; 0 on false;
*/
public function login_submit($user_login = null, $password = null, $is_ajax = true)
{
/**
* Verify the AJAX request
*/
if ($is_ajax) {
check_ajax_referer('login_submit', 'security');
}
$username = empty($_POST['user_login']) ? $user_login : sanitize_text_field($_POST['user_login']);
$password = empty($_POST['password']) ? $password : sanitize_text_field($_POST['password']);
$remember = !empty($_POST['rememberme']) ? true : false;
// Currently wp_signon returns the same error code 'invalid_username' if
// a username does not exists or is invalid
if (validate_username($username)) {
if (username_exists($username)) {
$creds = array('user_login' => $username, 'user_password' => $password, 'remember' => $remember);
$user = wp_signon($creds, false);
$status = is_wp_error($user) ? $this->status($user->get_error_code()) : $this->status('success_login');
} else {
$status = $this->status('username_does_not_exists');
}
} else {
$status = $this->status('invalid_username');
}
if ($is_ajax) {
wp_send_json($status);
} else {
return $status;
}
}
示例4: registration_validation
function registration_validation($username, $password, $email)
{
global $reg_errors;
$reg_errors = new WP_Error();
if (empty($username) || empty($password) || empty($email)) {
$reg_errors->add('field', 'Required form field is missing');
}
if (4 > strlen($username)) {
$reg_errors->add('username_length', 'Username too short. At least 4 characters is required');
}
if (username_exists($username)) {
$reg_errors->add('user_name', 'Sorry, that username already exists!');
}
if (!validate_username($username)) {
$reg_errors->add('username_invalid', 'Sorry, the username you entered is not valid');
}
if (5 > strlen($password)) {
$reg_errors->add('password', 'Password length must be greater than 5');
}
if (!is_email($email)) {
$reg_errors->add('email_invalid', 'Email is not valid');
}
if (email_exists($email)) {
$reg_errors->add('email', 'Email Already in use');
}
if (is_wp_error($reg_errors)) {
foreach ($reg_errors->get_error_messages() as $error) {
echo '<div>';
echo '<strong>ERROR</strong>:';
echo $error . '<br/>';
echo '</div>';
}
}
}
示例5: wppb_check_username_value
function wppb_check_username_value($message, $field, $request_data, $form_location)
{
global $wpdb;
if ($field['required'] == 'Yes') {
if (isset($request_data['username']) && trim($request_data['username']) == '' || $form_location == 'register' && !isset($request_data['username'])) {
return wppb_required_field_error($field["field-title"]);
}
}
if (!empty($request_data['username'])) {
if ($form_location == 'register') {
$search_by_user_login = get_users('search=' . $request_data['username']);
}
if (!empty($search_by_user_login)) {
return __('This username already exists.', 'profile-builder') . '<br/>' . __('Please try a different one!', 'profile-builder');
}
if (!validate_username($request_data['username'])) {
return __('This username is invalid because it uses illegal characters.', 'profile-builder') . '<br/>' . __('Please enter a valid username.', 'profile-builder');
}
$wppb_generalSettings = get_option('wppb_general_settings');
if ($wppb_generalSettings['emailConfirmation'] == 'yes') {
if (is_multisite() && $request_data['username'] != preg_replace('/\\s+/', '', $request_data['username'])) {
return __('This username is invalid because it uses illegal characters.', 'profile-builder') . '<br/>' . __('Please enter a valid username.', 'profile-builder');
}
$userSignup = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "signups WHERE user_login = %s", $request_data['username']));
if (!empty($userSignup)) {
return __('This username is already reserved to be used soon.', 'profile-builder') . '<br/>' . __('Please try a different one!', 'profile-builder');
}
}
}
return $message;
}
示例6: isValidUsername
public static function isValidUsername(\PropertyInterface $prop, $value = null, array $params = array())
{
try {
return validate_username($value);
} catch (\Exception $ex) {
throw new \hypeJunction\Exceptions\ActionValidationException($ex->getMessage());
}
}
示例7: process_registration
/**
* Process registration form submission
*
* @since 1.0
*/
public function process_registration($data)
{
if (!isset($_POST['affwp_register_nonce']) || !wp_verify_nonce($_POST['affwp_register_nonce'], 'affwp-register-nonce')) {
return;
}
do_action('affwp_pre_process_register_form');
if (!is_user_logged_in()) {
// Loop through required fields and show error message
foreach ($this->required_fields() as $field_name => $value) {
if (empty($_POST[$field_name])) {
$this->add_error($value['error_id'], $value['error_message']);
}
}
if (username_exists($data['affwp_user_login'])) {
$this->add_error('username_unavailable', __('Username already taken', 'affiliate-wp'));
}
if (!validate_username($data['affwp_user_login'])) {
if (is_multisite()) {
$this->add_error('username_invalid', __('Invalid username. Only lowercase letters (a-z) and numbers are allowed', 'affiliate-wp'));
} else {
$this->add_error('username_invalid', __('Invalid username', 'affiliate-wp'));
}
}
if (email_exists($data['affwp_user_email'])) {
$this->add_error('email_unavailable', __('Email address already taken', 'affiliate-wp'));
}
if (empty($data['affwp_user_email']) || !is_email($data['affwp_user_email'])) {
$this->add_error('email_invalid', __('Invalid email', 'affiliate-wp'));
}
if (!empty($data['affwp_payment_email']) && $data['affwp_payment_email'] != $data['affwp_user_email'] && !is_email($data['affwp_payment_email'])) {
$this->add_error('payment_email_invalid', __('Invalid payment email', 'affiliate-wp'));
}
if (!empty($_POST['affwp_user_pass']) && empty($_POST['affwp_user_pass2']) || $_POST['affwp_user_pass'] !== $_POST['affwp_user_pass2']) {
$this->add_error('password_mismatch', __('Passwords do not match', 'affiliate-wp'));
}
}
$terms_of_use = affiliate_wp()->settings->get('terms_of_use');
if (!empty($terms_of_use) && empty($_POST['affwp_tos'])) {
$this->add_error('empty_tos', __('Please agree to our terms of use', 'affiliate-wp'));
}
if (!empty($_POST['affwp_honeypot'])) {
$this->add_error('spam', __('Nice try honey bear, don\'t touch our honey', 'affiliate-wp'));
}
if (affwp_is_affiliate()) {
$this->add_error('already_registered', __('You are already registered as an affiliate', 'affiliate-wp'));
}
do_action('affwp_process_register_form');
// only log the user in if there are no errors
if (empty($this->errors)) {
$this->register_user();
$redirect = apply_filters('affwp_register_redirect', $data['affwp_redirect']);
if ($redirect) {
wp_redirect($redirect);
exit;
}
}
}
示例8: registration
public function registration($userdata)
{
$reg_errors = new WP_Error();
if (!isset($userdata) && empty($userdata) && !is_array($userdata)) {
$reg_errors->add('data_invalid', 'Chybí vstupní data');
return $reg_errors;
}
$userLogin = array_key_exists('user_login', $userdata) ? sanitize_user($userdata['user_login']) : '';
$userPass = array_key_exists('user_pass', $userdata) ? esc_attr($userdata['user_pass']) : '';
$userEmail = array_key_exists('user_email', $userdata) ? sanitize_email($userdata['user_email']) : '';
$userUrl = array_key_exists('user_url', $userdata) ? esc_url($userdata['user_url']) : '';
$firstName = array_key_exists('first_name', $userdata) ? sanitize_text_field($userdata['first_name']) : '';
$lastName = array_key_exists('last_name', $userdata) ? sanitize_text_field($userdata['last_name']) : '';
$nickname = array_key_exists('nickname', $userdata) ? sanitize_text_field($userdata['nickname']) : '';
$description = array_key_exists('description', $userdata) ? sanitize_text_field($userdata['description']) : '';
if (empty($userLogin) || empty($userPass) || empty($userEmail)) {
$reg_errors->add('field', 'Nejsou vyplnněny povinné pole formuláře.');
}
if (4 > strlen($userLogin)) {
$reg_errors->add('username_length', 'Příliš krátké uživatelské jméno. Zadejte minimálně 5 znaků.');
}
if (username_exists($userLogin)) {
$reg_errors->add('user_name', 'Je nám líto ale uživatelské jméno již existuje.');
}
if (!validate_username($userLogin)) {
$reg_errors->add('username_invalid', 'Neplatné uživatelské jméno.');
}
if (5 > strlen($userPass)) {
$reg_errors->add('password', 'Heslo musí obsahovat minimálně 6 znaků.');
}
if (!is_email($userEmail)) {
$reg_errors->add('email_invalid', 'Zadaný e-mail je ve špatném formátu.');
}
if (email_exists($userEmail)) {
$reg_errors->add('email', 'Zadaný e-mail již existuje.');
}
if (!empty($userUrl)) {
if (!filter_var($userUrl, FILTER_VALIDATE_URL)) {
$reg_errors->add('website', 'Url adresa Vašich stránek není validní.');
}
}
if (is_wp_error($reg_errors) && count($reg_errors->errors) > 0) {
return $reg_errors;
}
$_userdata = array('user_login' => $userLogin, 'user_email' => $userEmail, 'user_pass' => $userPass, 'user_url' => $userUrl, 'first_name' => $firstName, 'last_name' => $lastName, 'nickname' => $nickname, 'description' => $description, 'role' => 'customer');
$user_id = wp_insert_user($_userdata);
if (is_wp_error($user_id)) {
$reg_errors->add('insert_user', 'Registraci nelze dokončit. Kontaktujte prosím správce webu.');
return $reg_errors;
}
// Woocomerce data
if (array_key_exists('billing_first_name', $userdata)) {
add_user_meta($user_id, $meta_key, $meta_value, $unique);
}
$description = array_key_exists('description', $userdata) ? sanitize_text_field($userdata['description']) : '';
return $user_id;
}
示例9: reales_user_signup_form
function reales_user_signup_form()
{
$signup_user = isset($_POST['signup_user']) ? sanitize_text_field($_POST['signup_user']) : '';
$signup_firstname = isset($_POST['signup_firstname']) ? sanitize_text_field($_POST['signup_firstname']) : '';
$signup_lastname = isset($_POST['signup_lastname']) ? sanitize_text_field($_POST['signup_lastname']) : '';
$signup_email = isset($_POST['signup_email']) ? sanitize_email($_POST['signup_email']) : '';
$signup_pass_1 = isset($_POST['signup_pass_1']) ? $_POST['signup_pass_1'] : '';
$signup_pass_2 = isset($_POST['signup_pass_2']) ? $_POST['signup_pass_2'] : '';
$register_as_agent = isset($_POST['register_as_agent']) ? sanitize_text_field($_POST['register_as_agent']) : '';
if (empty($signup_user) || empty($signup_firstname) || empty($signup_lastname) || empty($signup_email) || empty($signup_pass_1) || empty($signup_pass_2)) {
echo json_encode(array('signedup' => false, 'message' => __('Required form fields are empty!', 'reales')));
exit;
}
if (4 > strlen($signup_user)) {
echo json_encode(array('signedup' => false, 'message' => __('Username too short. Please enter at least 4 characters!', 'reales')));
exit;
}
if (username_exists($signup_user)) {
echo json_encode(array('signedup' => false, 'message' => __('Username already exists!', 'reales')));
exit;
}
if (!validate_username($signup_user)) {
echo json_encode(array('signedup' => false, 'message' => __('Invalid Username!', 'reales')));
exit;
}
if (!is_email($signup_email)) {
echo json_encode(array('signedup' => false, 'message' => __('Invalid Email!', 'reales')));
exit;
}
if (email_exists($signup_email)) {
echo json_encode(array('signedup' => false, 'message' => __('Email already exists!', 'reales')));
exit;
}
if (6 > strlen($signup_pass_1)) {
echo json_encode(array('signedup' => false, 'message' => __('Password too short. Please enter at least 6 characters!', 'reales')));
exit;
}
if ($signup_pass_1 != $signup_pass_2) {
echo json_encode(array('reset' => false, 'message' => __('The passwords do not match!', 'reales')));
exit;
}
$user_data = array('user_login' => sanitize_user($signup_user), 'user_email' => sanitize_email($signup_email), 'user_pass' => esc_attr($signup_pass_1), 'first_name' => sanitize_text_field($signup_firstname), 'last_name' => sanitize_text_field($signup_lastname));
$new_user = wp_insert_user($user_data);
if (is_wp_error($new_user)) {
echo json_encode(array('signedup' => false, 'message' => __('Something went wrong!', 'reales')));
exit;
} else {
echo json_encode(array('signedup' => true, 'message' => __('Congratulations! You have successfully signed up.', 'reales')));
reales_signup_notifications($new_user, $signup_pass_1);
if ($register_as_agent != '' && $register_as_agent == 'true') {
reales_register_agent($new_user);
}
}
die;
}
示例10: createUserFromPatreon
public static function createUserFromPatreon($user_response, $tokens)
{
global $wpdb;
$email = $user_response['data']['attributes']['email'];
$name = strtolower(str_replace(' ', '', $user_response['data']['attributes']['first_name'] . '_' . $user_response['data']['attributes']['last_name']));
if (validate_username($name) && username_exists($name) == false) {
$username = sanitize_user($name, true);
} else {
$username = explode('@', $user_response['data']['attributes']['email']);
$username = strtolower(sanitize_user($username[0]));
}
if (username_exists($username)) {
$suffix = $wpdb->get_var($wpdb->prepare("SELECT 1 + SUBSTR(user_login, %d) FROM {$wpdb->users} WHERE user_login REGEXP %s ORDER BY 1 DESC LIMIT 1", strlen($username) + 2, '^' . $username . '(\\.[0-9]+)?$'));
if (!empty($suffix)) {
$username .= ".{$suffix}";
}
}
$user = get_user_by('email', $email);
if ($user == false) {
/* create wordpress user if no account exists with provided email address */
$random_password = wp_generate_password(12, false);
$user_id = wp_create_user($username, $random_password, $email);
if ($user_id) {
$user = get_user_by('id', $user_id);
wp_set_current_user($user->ID, $user->user_login);
wp_set_auth_cookie($user->ID);
do_action('wp_login', $user->user_login);
/* update user meta data with patreon data */
update_user_meta($user_id, 'patreon_refresh_token', $tokens['refresh_token']);
update_user_meta($user_id, 'patreon_access_token', $tokens['access_token']);
update_user_meta($user_id, 'patreon_user', $user_response['data']['attributes']['vanity']);
update_user_meta($user_id, 'patreon_created', $user_response['data']['attributes']['created']);
update_user_meta($user_id, 'user_firstname', $user_response['data']['attributes']['first_name']);
update_user_meta($user_id, 'user_lastname', $user_response['data']['attributes']['last_name']);
update_user_meta($user_id, 'patreon_token_minted', microtime());
} else {
/* wordpress account creation failed #HANDLE_ERROR */
}
} else {
/* log user into existing wordpress account with matching email address -- disabled */
// wp_set_current_user( $user->ID, $user->user_login );
// wp_set_auth_cookie( $user->ID );
// do_action( 'wp_login', $user->user_login );
/* update user meta data with patreon data */
update_user_meta($user->ID, 'patreon_refresh_token', $tokens['refresh_token']);
update_user_meta($user->ID, 'patreon_access_token', $tokens['access_token']);
update_user_meta($user->ID, 'patreon_user', $user_response['data']['attributes']['vanity']);
update_user_meta($user->ID, 'patreon_created', $user_response['data']['attributes']['created']);
update_user_meta($user->ID, 'user_firstname', $user_response['data']['attributes']['first_name']);
update_user_meta($user->ID, 'user_lastname', $user_response['data']['attributes']['last_name']);
wp_redirect(wp_login_url() . '?patreon-msg=login_with_patreon', '301');
exit;
}
}
示例11: wc_create_new_customer
/**
* Create a new customer
*
* @param string $email
* @param string $username
* @param string $password
* @return WP_Error on failure, Int (user ID) on success
*/
function wc_create_new_customer($email, $username = '', $password = '')
{
// Check the e-mail address
if (empty($email) || !is_email($email)) {
return new WP_Error("registration-error", __("Please provide a valid email address.", "woocommerce"));
}
if (email_exists($email)) {
return new WP_Error("registration-error", __("An account is already registered with your email address. Please login.", "woocommerce"));
}
wp_verify_nonce($_POST['register'], 'woocommerce-register');
// Handle username creation
if (get_option('woocommerce_registration_generate_username') == 'no' || !empty($username)) {
$username = sanitize_user($username);
if (empty($username) || !validate_username($username)) {
return new WP_Error("registration-error", __("Please enter a valid account username.", "woocommerce"));
}
if (username_exists($username)) {
return new WP_Error("registration-error", __("An account is already registered with that username. Please choose another.", "woocommerce"));
}
} else {
$username = sanitize_user(current(explode('@', $email)));
// Ensure username is unique
$append = 1;
$o_username = $username;
while (username_exists($username)) {
$username = $o_username . $append;
$append++;
}
}
// Handle password creation
if (get_option('woocommerce_registration_generate_password') == 'yes' && empty($password)) {
$password = wp_generate_password();
$password_generated = true;
} elseif (empty($password)) {
return new WP_Error("registration-error", __("Please enter an account password.", "woocommerce"));
} else {
$password_generated = false;
}
// WP Validation
$validation_errors = new WP_Error();
do_action('woocommerce_register_post', $username, $email, $validation_errors);
$validation_errors = apply_filters('woocommerce_registration_errors', $validation_errors, $username, $email);
if ($validation_errors->get_error_code()) {
return $validation_errors;
}
$new_customer_data = apply_filters('woocommerce_new_customer_data', array('user_login' => $username, 'user_pass' => $password, 'user_email' => $email, 'role' => 'customer'));
$customer_id = wp_insert_user($new_customer_data);
if (is_wp_error($customer_id)) {
return new WP_Error("registration-error", '<strong>' . __('ERROR', 'woocommerce') . '</strong>: ' . __('Couldn’t register you… please contact us if you continue to have problems.', 'woocommerce'));
}
do_action('woocommerce_created_customer', $customer_id, $new_customer_data, $password_generated);
return $customer_id;
}
示例12: acl_bp_core_validate_user_signup
function acl_bp_core_validate_user_signup($result)
{
$illegal_names = get_site_option('illegal_names');
if (validate_username($result['user_name']) && !in_array($result['user_name'], (array) $illegal_names)) {
$error_index = array_search(__('Only lowercase letters and numbers allowed', 'buddypress'), $result['errors']->errors['user_name']);
if (isset($error_index)) {
unset($result['errors']->errors['user_name'][$error_index]);
sort($result['errors']->errors['user_name']);
}
}
return $result;
}
示例13: wc_create_new_customer
/**
* Create a new customer.
*
* @param string $email Customer email.
* @param string $username Customer username.
* @param string $password Customer password.
* @return int|WP_Error Returns WP_Error on failure, Int (user ID) on success.
*/
function wc_create_new_customer($email, $username = '', $password = '')
{
// Check the email address.
if (empty($email) || !is_email($email)) {
return new WP_Error('registration-error-invalid-email', __('Please provide a valid email address.', 'woocommerce'));
}
if (email_exists($email)) {
return new WP_Error('registration-error-email-exists', __('An account is already registered with your email address. Please login.', 'woocommerce'));
}
// Handle username creation.
if ('no' === get_option('woocommerce_registration_generate_username') || !empty($username)) {
$username = sanitize_user($username);
if (empty($username) || !validate_username($username)) {
return new WP_Error('registration-error-invalid-username', __('Please enter a valid account username.', 'woocommerce'));
}
if (username_exists($username)) {
return new WP_Error('registration-error-username-exists', __('An account is already registered with that username. Please choose another.', 'woocommerce'));
}
} else {
$username = sanitize_user(current(explode('@', $email)), true);
// Ensure username is unique.
$append = 1;
$o_username = $username;
while (username_exists($username)) {
$username = $o_username . $append;
$append++;
}
}
// Handle password creation.
if ('yes' === get_option('woocommerce_registration_generate_password') && empty($password)) {
$password = wp_generate_password();
$password_generated = true;
} elseif (empty($password)) {
return new WP_Error('registration-error-missing-password', __('Please enter an account password.', 'woocommerce'));
} else {
$password_generated = false;
}
// Use WP_Error to handle registration errors.
$errors = new WP_Error();
do_action('woocommerce_register_post', $username, $email, $errors);
$errors = apply_filters('woocommerce_registration_errors', $errors, $username, $email);
if ($errors->get_error_code()) {
return $errors;
}
$new_customer_data = apply_filters('woocommerce_new_customer_data', array('user_login' => $username, 'user_pass' => $password, 'user_email' => $email, 'role' => 'customer'));
$customer_id = wp_insert_user($new_customer_data);
if (is_wp_error($customer_id)) {
return new WP_Error('registration-error', '<strong>' . __('Error:', 'woocommerce') . '</strong> ' . __('Couldn’t register you… please contact us if you continue to have problems.', 'woocommerce'));
}
do_action('woocommerce_created_customer', $customer_id, $new_customer_data, $password_generated);
return $customer_id;
}
示例14: validate_credentials
function validate_credentials($form)
{
$errors = [];
$userNameValid = validate_username($form);
if (!$userNameValid) {
$errors["validation.userName"] = "User name is required and should be an email address";
}
$passwordValid = validate_password($form);
if (!$passwordValid) {
$errors["validation.password"] = "Password is required and should have at least 4 characters";
}
return $errors;
}
示例15: forms_register_generate_username
/**
* Generates a unique available and valid username
*
* @param string $username Username prefix
* @return string
*/
function forms_register_generate_username($username = '')
{
$available = false;
$username = iconv('UTF-8', 'ASCII//TRANSLIT', $username);
$blacklist = '/[\\x{0080}-\\x{009f}\\x{00a0}\\x{2000}-\\x{200f}\\x{2028}-\\x{202f}\\x{3000}\\x{e000}-\\x{f8ff}]/u';
$blacklist2 = array(' ', '\'', '/', '\\', '"', '*', '&', '?', '#', '%', '^', '(', ')', '{', '}', '[', ']', '~', '?', '<', '>', ';', '|', '¬', '`', '@', '-', '+', '=');
$username = preg_replace($blacklist, '', $username);
$username = str_replace($blacklist2, '.', $username);
$ia = elgg_set_ignore_access(true);
$ha = access_get_show_hidden_status();
access_show_hidden_entities(true);
$minlength = elgg_get_config('minusername') ?: 4;
if ($username) {
$fill = $minlength - strlen($username);
} else {
$fill = 8;
}
$algo = elgg_get_plugin_setting('autogen_username_algo', 'forms_register', 'first_name_only');
if ($algo == 'full_name' && $fill <= 0) {
$separator = '.';
} else {
$separator = '';
}
if ($fill > 0) {
$suffix = (new ElggCrypto())->getRandomString($fill);
$username = "{$username}{$separator}{$suffix}";
}
$iterator = 0;
while (!$available) {
if ($iterator > 0) {
$username = "{$username}{$separator}{$iterator}";
}
$user = get_user_by_username($username);
$available = !$user;
try {
if ($available) {
validate_username($username);
}
} catch (Exception $e) {
if ($iterator >= 100) {
// too many failed attempts
$username = (new ElggCrypto())->getRandomString(8);
}
}
$iterator++;
}
access_show_hidden_entities($ha);
elgg_set_ignore_access($ia);
return strtolower($username);
}