function wp_login($username, $password, $already_md5 = false) { global $db, $error; if ('' == $username) { return false; } if ('' == $password) { $error = __('<strong>Error</strong>: The password field is empty.'); return false; } $user = new WP_User($username); if (!$user || !$user->ID) { $error = __('<strong>Error</strong>: Wrong username.'); return false; } if (!WP_Pass::check_password($password, $user->data->user_pass, $user->ID)) { $error = __('<strong>Error</strong>: Incorrect password.'); $pwd = ''; return false; } if (!$user->has_cap('supporter') && !$user->has_cap('supportpressadmin')) { return false; } return true; }
/** * Set $this as the current user if $password patches this user's password */ function login($password) { if (!WP_Pass::check_password($password, $this->user_pass, $this->id)) { return false; } $this->set_as_current(); return true; }
/** * Generates a random password drawn from the defined set of characters * @return string the password */ function bb_generate_password($length = 12, $special_chars = true) { return WP_Pass::generate_password($length, $special_chars); }
/** * set_password() - Updates the user's password with a new encrypted one * * For integration with other applications, this function can be * overwritten to instead use the other package password checking * algorithm. * * @since 2.5 * @uses WP_Pass::hash_password() Used to encrypt the user's password before passing to the database * * @param string $password The plaintext new user password * @param int $user_id User ID */ function set_password($password, $user_id) { $user = $this->get_user($user_id); if (!$user || is_wp_error($user)) { return $user; } $user_id = $user->ID; $hash = WP_Pass::hash_password($password); $this->update_user($user->ID, array('user_pass' => $password)); }
/** * Generates a random password drawn from the defined set of characters * * @since WP 2.5 * * @param int $length The length of password to generate * @param bool $special_chars Whether to include standard special characters * @return string The random password */ function generate_password($length = 12, $special_chars = true) { $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; if ($special_chars) { $chars .= '!@#$%^&*()'; } $password = ''; for ($i = 0; $i < $length; $i++) { $password .= substr($chars, WP_Pass::rand(0, strlen($chars) - 1), 1); } return $password; }
function sp_hash($s) { return WP_Pass::hash_password($s); }