本文整理汇总了PHP中wp_authenticate函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_authenticate函数的具体用法?PHP wp_authenticate怎么用?PHP wp_authenticate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_authenticate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: json_basic_auth_handler
/**
* Plugin Name: JSON Basic Authentication
* Description: Basic Authentication handler for the JSON API, used for development and debugging purposes
* Author: WordPress API Team
* Author URI: https://github.com/WP-API
* Version: 0.1
* Plugin URI: https://github.com/WP-API/Basic-Auth
*/
function json_basic_auth_handler($user)
{
global $wp_json_basic_auth_error;
$wp_json_basic_auth_error = null;
// Don't authenticate twice
if (!empty($user)) {
return $user;
}
// Check that we're trying to authenticate
if (!isset($_SERVER['PHP_AUTH_USER'])) {
return $user;
}
$username = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
/**
* In multi-site, wp_authenticate_spam_check filter is run on authentication. This filter calls
* get_currentuserinfo which in turn calls the determine_current_user filter. This leads to infinite
* recursion and a stack overflow unless the current function is removed from the determine_current_user
* filter during authentication.
*/
remove_filter('determine_current_user', 'json_basic_auth_handler', 20);
$user = wp_authenticate($username, $password);
add_filter('determine_current_user', 'json_basic_auth_handler', 20);
if (is_wp_error($user)) {
$wp_json_basic_auth_error = $user;
return null;
}
$wp_json_basic_auth_error = true;
return $user->ID;
}
开发者ID:walkthenight,项目名称:walkthenight-wordpress,代码行数:38,代码来源:basic-auth.php
示例2: generate_auth_cookie
public function generate_auth_cookie($args)
{
/**
* @var $nonce
* @var $username
* @var $password
*
*/
extract($args);
if (!wp_verify_nonce($nonce, 'auth_gmapp')) {
return array('error' => array('code' => 'nononce', 'message' => "Something goes wrong (nonce error)... try again."));
}
if (!$username) {
return array('error' => array('code' => 'nologin', 'message' => "You must include a 'username' var in your request."));
}
if (!$password) {
return array('error' => array('code' => 'nopassword', 'message' => "You must include a 'password' var in your request."));
}
$user = wp_authenticate($username, $password);
if (is_wp_error($user)) {
remove_action('wp_login_failed', $username);
return array('error' => array('code' => 'passerror', 'message' => "Invalid username and/or password."));
}
$expiration = time() + apply_filters('auth_cookie_expiration', 1209600, $user->ID, true);
$cookie = wp_generate_auth_cookie($user->ID, $expiration, 'logged_in');
preg_match('|src="(.+?)"|', get_avatar($user->ID, 32), $avatar);
if (!isset($avatar[1])) {
$avatar[1] = '';
}
return array("cookie" => $cookie, "user" => array("id" => $user->ID, "username" => $user->user_login, "nicename" => $user->user_nicename, "email" => $user->user_email, "url" => $user->user_url, "registered" => $user->user_registered, "displayname" => $user->display_name, "firstname" => $user->user_firstname, "lastname" => $user->last_name, "nickname" => $user->nickname, "description" => $user->user_description, "capabilities" => $user->wp_capabilities, "avatar" => $avatar[1]));
}
开发者ID:HugoLS,项目名称:Variation,代码行数:31,代码来源:json.auth.php
示例3: json_basic_auth_handler
/**
* Plugin Name: JSON Basic Authentication
* Description: Basic Authentication handler for the JSON API, used for development and debugging purposes
* Author: WordPress API Team
* Author URI: https://github.com/WP-API
* Version: 0.1
* Plugin URI: https://github.com/WP-API/Basic-Auth
*/
function json_basic_auth_handler($request)
{
global $wp_json_basic_auth_error;
$wp_json_basic_auth_error = null;
// Check that we're trying to authenticate
if (!isset($_SERVER['PHP_AUTH_USER'])) {
return $request;
}
$username = $_SERVER['PHP_AUTH_USER'];
$is_email = strpos($username, '@');
if ($is_email) {
$ud = get_user_by_email($username);
$username = $ud->user_login;
}
$password = $_SERVER['PHP_AUTH_PW'];
$user = wp_authenticate($username, $password);
if ($user) {
wp_set_current_user($user->ID, $user->user_login);
wp_set_auth_cookie($user->ID);
do_action('wp_login', $user->user_login);
}
/**
* In multi-site, wp_authenticate_spam_check filter is run on authentication. This filter calls
* get_currentuserinfo which in turn calls the determine_current_user filter. This leads to infinite
* recursion and a stack overflow unless the current function is removed from the determine_current_user
* filter during authentication.
*/
if (is_wp_error($user)) {
$wp_json_basic_auth_error = $user;
return null;
}
$wp_json_basic_auth_error = true;
return null;
}
开发者ID:gopaulo,项目名称:Basic-Auth,代码行数:42,代码来源:basic-auth.php
示例4: generate_auth_cookie
public function generate_auth_cookie()
{
global $json_api;
if (!$json_api->query->username) {
$json_api->error("You must include a 'username' var in your request.");
}
if (!$json_api->query->password) {
$json_api->error("You must include a 'password' var in your request.");
}
if ($json_api->query->seconds) {
$seconds = (int) $json_api->query->seconds;
} else {
$seconds = 1209600;
}
//14 days
$user = wp_authenticate($json_api->query->username, $json_api->query->password);
if (is_wp_error($user)) {
$json_api->error("Invalid username and/or password.", 'error', '401');
remove_action('wp_login_failed', $json_api->query->username);
}
$expiration = time() + apply_filters('auth_cookie_expiration', $seconds, $user->ID, true);
$cookie = wp_generate_auth_cookie($user->ID, $expiration, 'logged_in');
preg_match('|src="(.+?)"|', get_avatar($user->ID, 32), $avatar);
return array("cookie" => $cookie, "cookie_name" => LOGGED_IN_COOKIE, "user" => array("id" => $user->ID, "username" => $user->user_login, "nicename" => $user->user_nicename, "email" => $user->user_email, "url" => $user->user_url, "registered" => $user->user_registered, "displayname" => $user->display_name, "firstname" => $user->user_firstname, "lastname" => $user->last_name, "nickname" => $user->nickname, "description" => $user->user_description, "capabilities" => $user->wp_capabilities, "avatar" => $avatar[1]));
}
开发者ID:axeljohansson1988,项目名称:oddcv,代码行数:25,代码来源:Auth.php
示例5: authenticateAction
/**
* Handle login submissions. Authenticate using AuthService.
* @return
*/
public function authenticateAction()
{
$form = $this->getForm();
$urlRedirect = false;
$redirect = 'home';
$params = array();
$request = $this->getRequest();
if ($request->isPost()) {
$form->setData($request->getPost());
if ($form->isValid()) {
/* Handle Authentication */
$username = $request->getPost('Username');
$password = $request->getPost('Password');
$WP_User = wp_authenticate($username, $password);
if (is_wp_error($WP_User)) {
$redirect = 'login';
$this->flashmessenger()->addErrorMessage("Invalid User Credentials");
} else {
wp_set_auth_cookie($WP_User->ID);
$this->flashmessenger()->addSuccessMessage("Login Successful");
}
} else {
/* Form error messages */
foreach ($form->getMessages() as $message) {
$this->flashmessenger()->addErrorMessage(implode(",", $message));
}
}
}
return $this->redirect()->toRoute($redirect);
}
开发者ID:Ellipizle,项目名称:zf2-wordpress,代码行数:34,代码来源:AuthController.php
示例6: user_pass_ok
function user_pass_ok($user_login,$user_pass) {
$user = wp_authenticate($user_login, $user_pass);
if ( is_wp_error($user) )
return false;
return true;
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:7,代码来源:user.php
示例7: simple_http_authentication
function simple_http_authentication()
{
if (is_wp_error(wp_authenticate($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']))) {
header('WWW-Authenticate: Basic realm="' . wp_title('-', false) . '"');
header('HTTP/1.0 401 Unauthorized');
echo __('You need to authenticate with a registered user on WordPress.', 'simple-http-authentication');
exit;
}
}
开发者ID:joaopaulin,项目名称:simple-http-authentication,代码行数:9,代码来源:simple-http-authentication.php
示例8: authenticate
protected function authenticate($username, $password)
{
$user = wp_authenticate($username, $password);
if (!$user || is_wp_error($user)) {
return null;
} else {
return $user->ID;
}
}
开发者ID:SkyFire-Lee,项目名称:x7chat,代码行数:9,代码来源:wordpress.php
示例9: token
public function token()
{
if (!($grant_type = $this->http->get('grant_type'))) {
status_header(401);
wp_send_json_error('The grant type was not specified in the request');
}
$types = array('client_credentials', 'password');
if (in_array($grant_type, $types)) {
if (!($client_id = $this->http->get('client_id'))) {
status_header(401);
wp_send_json_error('Missing parameter: client_id');
}
if (!($client_secret = $this->http->get('client_secret'))) {
status_header(401);
wp_send_json_error('Missing parameter: client_secret');
}
if (in_array($grant_type, array('password'))) {
if (!($username = $this->http->get('username'))) {
status_header(401);
wp_send_json_error('Missing parameter: username');
}
if (!($password = $this->http->get('password'))) {
status_header(401);
wp_send_json_error('Missing parameter: password');
}
}
if (is_array($this->settings['username'])) {
foreach ($this->settings['username'] as $property) {
if ($user = get_user_by($property, $username)) {
break;
}
}
} else {
$user = get_user_by($this->settings['username'], $username);
}
$is_authenticated = wp_authenticate($user->user_login, $password);
if (!is_wp_error($is_authenticated)) {
$token = wp_generate_password(40, false, false);
$tokens = get_user_meta($user->ID, 'access_token', false);
if (count($tokens) >= 5) {
delete_user_meta($user->ID, 'access_token', reset($tokens));
}
add_user_meta($user->ID, 'access_token', $token);
status_header(200);
wp_send_json_success(array('access_token' => $token, 'expires_in' => 3600, 'token_type' => 'Bearer', 'scope' => 'basic', 'refresh_token' => null));
} else {
status_header(401);
wp_send_json_error($is_authenticated->get_error_message());
}
} else {
status_header(401);
wp_send_json_error('Unsupported grant type: ' . $grant_type);
}
}
开发者ID:creativelittledots,项目名称:wp-kit-core,代码行数:54,代码来源:OauthAuth.php
示例10: check_xmlrpc
function check_xmlrpc($username, $password)
{
if (!get_option('enable_xmlrpc')) {
return new IXR_Error(405, sprintf(__('XML-RPC services are disabled on this blog. An admin user can enable them at %s'), admin_url('options-writing.php')));
}
$user = wp_authenticate($username, $password);
if (is_wp_error($user)) {
return new IXR_Error(403, __('Bad login/pass combination.'));
}
return true;
}
开发者ID:netconstructor,项目名称:cms_utility,代码行数:11,代码来源:wp-xml-featured.php
示例11: test_password_trimming
/**
* @ticket 23494
*/
function test_password_trimming()
{
$another_user = $this->factory->user->create(array('user_login' => 'password-triming-tests'));
$passwords_to_test = array('a password with no trailing or leading spaces', 'a password with trailing spaces ', ' a password with leading spaces', ' a password with trailing and leading spaces ');
foreach ($passwords_to_test as $password_to_test) {
wp_set_password($password_to_test, $another_user);
$authed_user = wp_authenticate('password-triming-tests', $password_to_test);
$this->assertInstanceOf('WP_User', $authed_user);
$this->assertEquals($another_user, $authed_user->ID);
}
}
开发者ID:boonebgorges,项目名称:wp,代码行数:14,代码来源:auth.php
示例12: _login
/**
* Login a user
* @param $username
* @param $password
* @return bool|WP_Error|WP_User
*/
function _login($username, $password, $blog_id = 1)
{
$retval = FALSE;
if (!is_a($user_obj = wp_authenticate($username, $password), 'WP_Error')) {
wp_set_current_user($user_obj->ID);
$retval = $user_obj;
if (is_multisite()) {
switch_to_blog($blog_id);
}
}
return $retval;
}
开发者ID:sallf,项目名称:coopernature,代码行数:18,代码来源:module.nextgen_xmlrpc.php
示例13: json_basic_auth_handler
/**
* Plugin Name: JSON Basic Authentication
* Description: Basic Authentication handler for the JSON API, used for development and debugging purposes
* Author: WordPress API Team
* Author URI: https://github.com/WP-API
* Version: 0.1
* Plugin URI: https://github.com/WP-API/Basic-Auth
*/
function json_basic_auth_handler($user)
{
global $wp_json_basic_auth_error;
$wp_json_basic_auth_error = null;
// Don't authenticate twice
if (!empty($user)) {
return $user;
}
//account for issue where some servers remove the PHP auth headers
//so instead look for auth info in a custom environment variable set by rewrite rules
//probably in .htaccess
if (!isset($_SERVER['PHP_AUTH_USER'])) {
if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
$header = $_SERVER['HTTP_AUTHORIZATION'];
} elseif (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
$header = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
} else {
$header = null;
}
if (!empty($header)) {
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode(substr($header, 6)));
}
}
// Check that we're trying to authenticate
if (!isset($_SERVER['PHP_AUTH_USER'])) {
return $user;
}
$username = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
/**
* In multi-site, wp_authenticate_spam_check filter is run on authentication. This filter calls
* get_currentuserinfo which in turn calls the determine_current_user filter. This leads to infinite
* recursion and a stack overflow unless the current function is removed from the determine_current_user
* filter during authentication.
*/
remove_filter('determine_current_user', 'json_basic_auth_handler', 20);
remove_filter('authenticate', 'wp_authenticate_spam_check', 99);
$user = wp_authenticate($username, $password);
add_filter('determine_current_user', 'json_basic_auth_handler', 20);
add_filter('authenticate', 'wp_authenticate_spam_check', 99);
if (is_wp_error($user)) {
$wp_json_basic_auth_error = $user;
return null;
}
$wp_json_basic_auth_error = true;
//if we found a user, remove regular cookie filters because
//they're just going to overwrite what we've found
if ($user->ID) {
remove_filter('determine_current_user', 'wp_validate_auth_cookie');
remove_filter('determine_current_user', 'wp_validate_logged_in_cookie', 20);
}
return $user->ID;
}
开发者ID:aaronfrey,项目名称:PepperLillie-GSP,代码行数:61,代码来源:basic-auth.php
示例14: test_ignore_password_change
function test_ignore_password_change()
{
$this->make_user_by_role('author');
$new_pass = 'newpassword';
$new_data = array('password' => $new_pass);
$result = $this->myxmlrpcserver->wp_editProfile(array(1, 'author', 'author', $new_data));
$this->assertNotInstanceOf('IXR_Error', $result);
$this->assertTrue($result);
$auth_old = wp_authenticate('author', 'author');
$auth_new = wp_authenticate('author', $new_pass);
$this->assertInstanceOf('WP_User', $auth_old);
$this->assertWPError($auth_new);
}
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:13,代码来源:editProfile.php
示例15: authorize_package_request
/**
* Authenticate requests for SatisPress packages using HTTP Basic Authentication.
*
* @since 0.2.0
*/
public function authorize_package_request()
{
$user = is_user_logged_in() ? wp_get_current_user() : false;
if (!$user && isset($_SERVER['PHP_AUTH_USER'])) {
$user = wp_authenticate($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
}
$user = apply_filters('satispress_pre_basic_authentication', $user);
// Request credentials if the user isn't logged in yet.
if (!$user || is_wp_error($user)) {
header('WWW-Authenticate: Basic realm="SatisPress"');
header('HTTP/1.0 401 Unauthorized');
exit;
}
}
开发者ID:blazersix,项目名称:satispress,代码行数:19,代码来源:class-satispress-authentication-basic.php
示例16: login
/**
* Log user in.
*
* @since 2.8
*
* @param string $username User's username.
* @param string $password User's password.
* @return mixed WP_User object if authentication passed, false otherwise
*/
function login($username, $password)
{
if (!get_option('enable_xmlrpc')) {
$this->error = new IXR_Error(405, sprintf(__('XML-RPC services are disabled on this blog. An admin user can enable them at %s'), admin_url('options-writing.php')));
return false;
}
$user = wp_authenticate($username, $password);
if (is_wp_error($user)) {
$this->error = new IXR_Error(403, __('Bad login/pass combination.'));
return false;
}
set_current_user($user->ID);
return $user;
}
开发者ID:rtgibbons,项目名称:bya.org,代码行数:23,代码来源:xmlrpc.php
示例17: login_ajax_request
function login_ajax_request()
{
$username = isset($_POST['username']) ? $_POST['username'] : null;
$password = isset($_POST['password']) ? $_POST['password'] : null;
$object = wp_authenticate($username, $password);
if (!$object instanceof WP_User) {
$json = json_encode(false);
} else {
wp_signon(array('user_login' => $username, 'user_password' => $password));
unset($object->data->user_pass);
$json = json_encode($object->data);
}
header("Content-type: application/json", true);
die($json);
}
开发者ID:Gabriel-Pereira-MJ,项目名称:participacao-tema,代码行数:15,代码来源:functions.php
示例18: as_secure_cookie
function as_secure_cookie($secure_cookie, $credentials)
{
global $use_ssl;
if (empty($credentials) || $use_ssl === false) {
as_log("Credentials empty or use_ssl is false");
return $secure_cookie;
} elseif ($use_ssl) {
as_log("Verifying user and setting HTTP auth cookie");
$user = wp_authenticate($credentials['user_login'], $credentials['user_password']);
//
// set the non-secure cookies and let WP set the secure cookie
//
wp_set_auth_cookie($user->ID, $credentials['remember'], false);
return true;
}
}
开发者ID:macconsultinggroup,项目名称:WordPress,代码行数:16,代码来源:https.php
示例19: process
public function process($ip, &$stats = array(), &$options = array(), &$post = array())
{
$sname = $this->getSname();
if (!class_exists('GoogleAuthenticator') && strpos($sname, 'wp-login.php') !== false && function_exists('wp_authenticate')) {
$log = $post['author'];
$pwd = $post['pwd'];
if (empty($log) || empty($pwd)) {
return false;
}
$user = @wp_authenticate($log, $pwd);
if (!is_wp_error($user)) {
// user login is good
return 'authenticated user login';
}
return false;
}
return false;
}
开发者ID:healthcommcore,项目名称:osnap,代码行数:18,代码来源:chkadminlog.php
示例20: isValid
public function isValid(array $values)
{
$valid = parent::isValid($values);
if (!$valid) {
return false;
}
$credentials = $values;
$user = wp_authenticate($credentials['user_login'], $credentials['user_password']);
if (is_wp_error($user)) {
if ($user->get_error_codes() == array('empty_username', 'empty_password')) {
$user = new WP_Error('', '');
}
return $user;
}
wp_set_auth_cookie($user->ID, $credentials['remember'], $secure_cookie);
do_action('wp_login', $credentials['user_login']);
return $user;
}
开发者ID:robjcordes,项目名称:nexnewwp,代码行数:18,代码来源:Login.php
注:本文中的wp_authenticate函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论