Example #1
0
 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;
     }
 }
Example #2
0
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;
}
Example #3
0
 /**
  * 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;
     }
 }
Example #4
0
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>';
        }
    }
}
Example #5
0
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;
}
Example #6
0
 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());
     }
 }
 /**
  * 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;
         }
     }
 }
 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;
 }
Example #9
0
 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;
 }
 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;
     }
 }
/**
 * 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&#8217;t register you&hellip; 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;
}
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;
}
 /**
  * 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&#8217;t register you&hellip; 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;
 }
function validate_credentials($form)
{
    $errors = [];
    $userNameValid = validate_username($form);
    if (!$userNameValid) {
        $errors["validation.userName"] = "******";
    }
    $passwordValid = validate_password($form);
    if (!$passwordValid) {
        $errors["validation.password"] = "******";
    }
    return $errors;
}
/**
 * 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 = "******";
    }
    $iterator = 0;
    while (!$available) {
        if ($iterator > 0) {
            $username = "******";
        }
        $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);
}
function verify_account($dirty_username, $dirty_password, $dirty_activation_code)
{
    $username = escape($dirty_username);
    $password = escape($dirty_password);
    $code = escape($dirty_activation_code);
    $validateUsrMsg = validate_username($username);
    if ($validateUsrMsg != "valid-username") {
        return;
    }
    $validatePwdMsg = validate_password($password);
    if ($validatePwdMsg != "valid-password") {
        return;
    }
    $account_id = account_id_from_code($code);
    $sql1 = "SELECT * FROM account_signup WHERE code='{$code}'";
    $result = query($sql1);
    if (mysqli_num_rows($result) == 1) {
        $row = mysqli_fetch_assoc($result);
        $date_requested = $row["date_requested"];
        $expires = $date_requested + 86400;
        if (time() > $expires) {
            echo "validation-expired";
            return;
        }
        $encrypted_password = encrypt_password($password);
        $sql2 = "UPDATE account_head SET status='logged-out' WHERE account={$account_id};";
        query($sql2);
        if (user_has_status($account_id, 'logged-out') == false) {
            echo 'verify-error';
            return;
        }
        $sql3 = "INSERT INTO account_credentials (account, username, password)";
        $sql3 .= " VALUES ({$account_id}, '{$username}', '{$encrypted_password}');";
        query($sql3);
        if (user_has_credentials($account_id, $username, $encrypted_password) == false) {
            echo 'verify-error';
            return;
        }
        $sql4 = "DELETE FROM account_signup WHERE account={$account_id};";
        query($sql4);
        if (user_has_signup_pending($account_id)) {
            echo 'verify-error';
            return;
        }
        echo "verify-success";
        return;
    }
    echo 'verify-error';
}
Example #17
0
    function new_user($user, $email, $password, $type)
    {
        validate_username($user);
        validate_password($password);

        $salt = sha1(time());

        $hashed_pass = sha1($salt . $password);

        $query = "INSERT INTO `users`
            (`User_name`, `Password`, `Salt`, `Type`, `Ppal_email`)
            VALUES ('@v','@v','@v', '@v', '@v')";

        $this->query($query, $user, $hashed_pass, $salt, $type, $email);
    }
Example #18
0
 public function isValid($value)
 {
     if ($value == '') {
         $this->setError(__('Please enter a username.', WPJB_DOMAIN));
         return false;
     } elseif (!validate_username($value)) {
         $this->setError(__('This username is invalid because it uses illegal characters. Please enter a valid username.', WPJB_DOMAIN));
         $value = '';
         return false;
     } elseif (username_exists($value)) {
         $this->setError(__('This username is already registered, please choose another one.', WPJB_DOMAIN));
         return false;
     }
     return true;
 }
Example #19
0
function rhm_ajax_register()
{
    $user_login = '';
    $user_email = '';
    extract($_POST);
    // Should include $user_login and $user_email.
    $errors = new WP_Error();
    $sanitized_user_login = sanitize_user($user_login);
    $user_email = apply_filters('user_registration_email', $user_email);
    // Check the username
    if ($sanitized_user_login == '') {
        $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.'));
    } elseif (!validate_username($user_login)) {
        $errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.'));
        $sanitized_user_login = '';
    } elseif (username_exists($sanitized_user_login)) {
        $errors->add('username_exists', __('<strong>ERROR</strong>: This username is already registered. Please choose another one.'));
    }
    // Check the e-mail address
    if ($user_email == '') {
        $errors->add('empty_email', __('<strong>ERROR</strong>: Please type your e-mail address.'));
    } elseif (!is_email($user_email)) {
        $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn&#8217;t correct.'));
        $user_email = '';
    } elseif (email_exists($user_email)) {
        $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.'));
    }
    do_action('register_post', $sanitized_user_login, $user_email, $errors);
    $errors = apply_filters('registration_errors', $errors, $sanitized_user_login, $user_email);
    if ($errors->get_error_code()) {
        echo $errors->get_error_message();
        die;
    }
    $user_pass = wp_generate_password(12, false);
    $user_id = wp_create_user($sanitized_user_login, $user_pass, $user_email);
    if (!$user_id) {
        $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email')));
        echo $errors->get_error_message();
        die;
    }
    update_user_option($user_id, 'default_password_nag', true, true);
    //Set up the Password change nag.
    wp_new_user_notification($user_id, $user_pass);
    echo '<strong>Success!</strong> Your registration is complete. A randomly-generated password has been emailed to you.';
    die;
}
Example #20
0
	/**
   *
   * Create Username
   *
   * Creates a username from the given first name and last name. Format is first initial and last name. If username exists, adds an integer to the end of the username.
   *
   * @author Ryan Bagwell <*****@*****.**>
   * @param string $first the person's first name
   * @param string $last the person's last name
   * @return the user name
   *
  */
	function create_username($first = null,$last = null) {
	
		$name = strtolower(substr($first,0,1) . $last);

		//if it's a valid combintion of their first initial and last name, return that
		if (validate_username($name) && is_null(username_exists($name)))
			return $name;
	
		//now loop through and add a number at the end until we find a valid name
		$i = 0;
		while($i < 10000) {
			if (validate_username($name.$i) && is_null(username_exists($name.$i)))
				var_dump($name.$i); 
				return $name.$i;
			$i++;	
		}
		
	}
 public static function yz_auth_register()
 {
     if (!isset($_SESSION)) {
         session_start();
         session_regenerate_id(TRUE);
     }
     $result = array("error_code" => 0, "error_msg" => "success", "data" => array());
     if (!get_option('users_can_register')) {
         $result['error_code'] = -2;
         $result['error_msg'] = "users can not register";
     }
     $user_login = isset($_POST['user_login']) ? $_POST['user_login'] : null;
     //$user_email = isset($_POST['user_email'])?$_POST['user_email']:null;
     $user_email = '';
     $password = isset($_POST['password']) ? $_POST['password'] : null;
     $captcha = isset($_POST['captcha']) ? $_POST['captcha'] : null;
     if (empty($user_login) || empty($password)) {
         $result['error_code'] = -1;
         $result['error_msg'] = "user_login or password or can not be null";
         //$result['data']  =  $_POST;
     }
     if (!validate_username($user_login)) {
         $result['error_code'] = -3;
         $result['error_msg'] = "invalid username";
     }
     /*
             if (empty($_SESSION['captcha']) || strtolower(trim($captcha)) != $_SESSION['captcha']) {
                 $result['error_code'] = -1;
                 $result['error_msg']  =  "captcha invalid ";
                 $result['data']  =  $_POST;	
                 $result['data']['sess_captcha']  =  $_SESSION['captcha'];	
             }
     */
     if (0 === $result['error_code']) {
         $user_id = wp_create_user($user_login, $password, $user_email);
         if (is_wp_error($user_id)) {
             $result['error_code'] = $user_id->get_error_code();
             $result['error_msg'] = implode(' ', $user_id->get_error_messages());
         } else {
             $result['data'] = array("uid" => $user_id);
         }
     }
     self::set_response($result);
 }
Example #22
0
 /**
  * Process request to pass variables into WordPress' validate_username();
  *
  * @uses validate_username()
  * @param $username (string)
  * @param $is_ajax (bool) Process as an AJAX request or not.
  */
 public function validate_username($username = null, $is_ajax = true)
 {
     $username = empty($_POST['login']) ? esc_attr($username) : esc_attr($_POST['login']);
     if (validate_username($username)) {
         $user_id = username_exists($username);
         if ($user_id) {
             $msg = $this->status('username_exists');
         } else {
             $msg = $this->status('valid_username');
         }
     } else {
         $msg = $this->status('invalid_username');
     }
     if ($is_ajax) {
         wp_send_json($msg);
     } else {
         return $msg;
     }
 }
Example #23
0
function prepare_post(&$mode, &$post_data, &$error_msg, &$username, &$subject, &$message)
{
    global $bb_cfg, $user, $userdata, $lang;
    // Check username
    if (!empty($username)) {
        $username = clean_username($username);
        if (!$userdata['session_logged_in'] || $userdata['session_logged_in'] && $username != $user->name) {
            require INC_DIR . 'functions_validate.php';
            if ($err = validate_username($username)) {
                $error_msg .= $err;
            }
        } else {
            $username = '';
        }
    }
    // Check subject
    if (!empty($subject)) {
        $subject = str_replace('&amp;', '&', $subject);
    } else {
        if ($mode == 'newtopic' || $mode == 'editpost' && $post_data['first_post']) {
            $error_msg .= !empty($error_msg) ? '<br />' . $lang['EMPTY_SUBJECT'] : $lang['EMPTY_SUBJECT'];
        }
    }
    // Check message
    if (!empty($message)) {
    } else {
        if ($mode != 'delete') {
            $error_msg .= !empty($error_msg) ? '<br />' . $lang['EMPTY_MESSAGE'] : $lang['EMPTY_MESSAGE'];
        }
    }
    // Check smilies limit
    if ($bb_cfg['max_smilies']) {
        $count_smilies = substr_count(bbcode2html($message), '<img class="smile" src="' . $bb_cfg['smilies_path']);
        if ($count_smilies > $bb_cfg['max_smilies']) {
            $to_many_smilies = sprintf($lang['MAX_SMILIES_PER_POST'], $bb_cfg['max_smilies']);
            $error_msg .= !empty($error_msg) ? '<br />' . $to_many_smilies : $to_many_smilies;
        }
    }
    if (IS_GUEST && !bb_captcha('check')) {
        $error_msg .= !empty($error_msg) ? '<br />' . $lang['CAPTCHA_WRONG'] : $lang['CAPTCHA_WRONG'];
    }
}
Example #24
0
 public static function login($result)
 {
     $Customer = ShoppOrder()->Customer;
     if ($Customer->loggedin()) {
         return $result;
     }
     $accounts = shopp_setting('account_system');
     $pleaselogin = '******' . Shopp::__('If you have an account with us, please login now.');
     // This specific !isset condition checks if the loginname is not provided
     // If no loginname is provided, but an account system is used, we need to
     // generate a new login name for the customer
     if ('wordpress' == $accounts && !isset($_POST['loginname'])) {
         ShoppLoginGenerator::object();
         $_POST['loginname'] = ShoppLoginGenerator::name();
         if (apply_filters('shopp_login_required', empty($_POST['loginname']))) {
             return shopp_add_error(Shopp::__('A login could not be created with the information you provided. Enter a different name or email address.') . $pleaselogin);
         }
         shopp_debug('Login set to ' . $_POST['loginname'] . ' for WordPress account creation.');
     }
     // Validate unique email address for new account
     if (in_array($accounts, array('wordpress', 'shopp')) && !$Customer->session(ShoppCustomer::GUEST)) {
         $ShoppCustomer = new ShoppCustomer($_POST['email'], 'email');
         if (apply_filters('shopp_email_exists', 'wordpress' == $accounts ? email_exists($_POST['email']) : $ShoppCustomer->exists())) {
             return shopp_add_error(Shopp::__('The email address you entered is already in use. Enter a different email address to create a new account.') . $pleaselogin);
         }
     }
     // Validate WP login
     if (isset($_POST['loginname'])) {
         if (apply_filters('shopp_login_required', empty($_POST['loginname']))) {
             return shopp_add_error(Shopp::__('You must enter a login name for your account.'));
         }
         if (apply_filters('shopp_login_valid', !validate_username($_POST['loginname']))) {
             $sanitized = sanitize_user($_POST['loginname'], true);
             $illegal = array_diff(str_split($_POST['loginname']), str_split($sanitized));
             return shopp_add_error(Shopp::__('The login name provided includes invalid characters: %s', esc_html(join(' ', $illegal))));
         }
         if (apply_filters('shopp_login_exists', username_exists($_POST['loginname']))) {
             return shopp_add_error(Shopp::__('&quot;%s&quot; is already in use. Enter a different login name to create a new account.', esc_html($_POST['loginname'])) . $pleaselogin);
         }
     }
     return $result;
 }
Example #25
0
/** Tarkasta rekister\"{o}intilomake
 * @param $email string 
 * @param $password string 
 * @param $username string 
 * @return boolean
 */
function validate($email, $password, $username)
{
    if (!validate_email($email)) {
        echo "email wrong";
        return false;
    } else {
        if (!validate_password($password)) {
            echo "password wrong";
            return false;
        } else {
            if (!validate_username($username)) {
                echo "username wrong";
                return false;
            } else {
                echo "correct validation";
                return true;
            }
        }
    }
}
function form_validation($uname, $pwd, $email, $dob, $sex, $state, $city, $news)
{
    $error_message = "";
    $error_message = validate_username($uname, $error_message);
    $error_message = validate_password($pwd, $error_message);
    $error_message = validate_email($email, $error_message);
    $error_message = validate_dob($dob, $error_message);
    $error_message = validate_sex($sex, $error_message);
    $error_message = validate_state($state, $error_message);
    $error_message = validate_city($city, $error_message);
    $error_message = validate_newsletter($news, $error_message);
    if ($error_message) {
        echo "<br>I am sorry, but you haven't filled the form correctly. Please check the following.<br><br>" . $error_message;
        // echo "I am now redirecting you to the previous page. Please fill it correctly this time.";
        // header ( "Location: ../Client/signup.html" );
        return 0;
    } else {
        return 1;
    }
}
Example #27
0
 /**
  * Check username
  *
  * @return object
  */
 public function username()
 {
     $username = utf8_normalize_nfc(request_var('username', '', true));
     if (strlen($username) > $this->config['max_name_chars']) {
         $return = $this->user->lang('USERNAME_CHARS_ANY_EXPLAIN', $this->config['min_name_chars'], $this->config['max_name_chars']);
     } else {
         if (strlen($username) < $this->config['min_name_chars']) {
             $return = $this->user->lang('USERNAME_CHARS_ANY_EXPLAIN', $this->config['min_name_chars'], $this->config['max_name_chars']);
         } else {
             if ($return = validate_username($username)) {
                 if ($return) {
                     $return = $this->user->lang($return . '_USERNAME');
                 }
             } else {
                 $return = 0;
             }
         }
     }
     return new Response($return);
 }
Example #28
0
/**
 * Handles registering a new user.
 *
 * @param string $user_login User's username for logging in
 * @param string $user_email User's email address to send password and add
 * @return int|WP_Error Either user's ID or error on failure.
 */
function register_new_user($user_login, $user_email)
{
    $errors = new WP_Error();
    $sanitized_user_login = sanitize_user($user_login);
    $user_email = apply_filters('user_registration_email', $user_email);
    // Check the username
    if ($sanitized_user_login == '') {
        $errors->add('empty_username', __('Error: Please enter a username.', 'cubell'));
    } elseif (!validate_username($user_login)) {
        $errors->add('invalid_username', __('Error: This username is invalid because it uses illegal characters. Please enter a valid username.', 'cubell'));
        $sanitized_user_login = '';
    } elseif (username_exists($sanitized_user_login)) {
        $errors->add('username_exists', __('Error:: This username is already registered. Please choose another one.', 'cubell'));
    }
    // Check the e-mail address
    if ($user_email == '') {
        $errors->add('empty_email', __('Error: Please type your e-mail address.', 'cubell'));
    } elseif (!is_email($user_email)) {
        $errors->add('invalid_email', __('Error: The email address isn&#8217;t correct.', 'cubell'));
        $user_email = '';
    } elseif (email_exists($user_email)) {
        $errors->add('email_exists', __('Error: This email is already registered, please choose another one.', 'cubell'));
    }
    do_action('register_post', $sanitized_user_login, $user_email, $errors);
    $errors = apply_filters('registration_errors', $errors, $sanitized_user_login, $user_email);
    if ($errors->get_error_code()) {
        return $errors;
    }
    $user_pass = wp_generate_password(12, false);
    $user_id = wp_create_user($sanitized_user_login, $user_pass, $user_email);
    if (!$user_id) {
        $errors->add('registerfail', sprintf(__('Error: Please contact the <a href="mailto:%s">webmaster</a>.', 'cubell'), get_option('admin_email')));
        return $errors;
    }
    update_user_option($user_id, 'default_password_nag', true, true);
    //Set up the Password change nag.
    wp_new_user_notification($user_id, $user_pass);
    return $user_id;
}
    function new_dm($user_id, $type, $remote_name, $remote_profile,
        $remote_avatar, $remote_message, $remote_time)
    {
        $users = instance_model('users');
        $users->verify_user_id($user_id);

        if(!($type == "public" || $type == 'private'))
            throw new invalid_dm_type_exception();

        validate_username($remote_name);
        validate_url($remote_profile);
        validate_avatar($remote_avatar);
        validate_message($remote_message);

        $query = "INSERT INTO `direct-message`
            (`User_ID`, `Type`, `Remote_name`, `Remote_profile`,
                `Remote_avatar`, `Remote_message`, `Remote_time`)
            VALUES ('@v','@v','@v','@v','@v', '@v', '@v')";

        $this->query($query, $user_id, $type, $remote_name,
            $remote_profile, $remote_avatar, $remote_message, $remote_time);
    }
    function new_user($user, $email, $password)
    {
        validate_username($user);
        validate_email($email);
        validate_password($password);

        $salt = sha1(time());

        $hashed_pass = sha1($salt . $password);

        $avatar = make_ext_url('media/default_avatar.jpg');

    // Generate a new RSA key pair
        $res = openssl_pkey_new();
        openssl_pkey_export($res, $priv_key);
        $pub_key = openssl_pkey_get_details($res);
        $pub_key = $pub_key['key'];

        $query = "INSERT INTO `users`
            (`User_name`, `E-mail`, `Password`, `Salt`, `Priv_key`, `Pub_key`, `Avatar`)
            VALUES ('@v','@v','@v','@v','@v','@v', '@v')";

        $this->query($query, $user, $email, $hashed_pass, $salt,
            base64_encode($priv_key), base64_encode($pub_key), $avatar);
    }