<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>logout &#8211; Blackbams Blog</title>
	<atom:link href="https://blog.blackbam.at/tag/logout/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.blackbam.at</link>
	<description>development - digital arts - internet</description>
	<lastBuildDate>Wed, 05 Oct 2011 17:25:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>
	<item>
		<title>WordPress custom external authentication login/logout PHP script</title>
		<link>https://blog.blackbam.at/2011/06/09/wordpress-custom-external-authentication-loginlogout-php-script/</link>
					<comments>https://blog.blackbam.at/2011/06/09/wordpress-custom-external-authentication-loginlogout-php-script/#comments</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Thu, 09 Jun 2011 21:31:19 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP Scripts]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[custom script]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[logout]]></category>
		<category><![CDATA[wp_authenticate]]></category>
		<category><![CDATA[wp_login]]></category>
		<category><![CDATA[wp_signon]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1424</guid>

					<description><![CDATA[Recently I was confronted with the problem to have multiple user types on a WordPress Blog who needed to be logged in using an external service/authentication mechanism partly. But they all had to use the same login form for the system. A common problem? The WordPress Function Reference and  Codex do not document this topic [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Recently I was confronted with the problem to have multiple user types on a WordPress Blog who needed to be logged in using an external service/authentication mechanism partly. But they all had to use the same login form for the system. A common problem? The WordPress Function Reference and  Codex do not document this topic very well and it took me a lot of time to figure out how to do this best, so I want to keep it for the future and provide it to my blog visitors.</p>
<p>&nbsp;</p>
<h3>Override the WordPress default login action</h3>
<p>&nbsp;</p>
<p>Write the following to your functions.php-file:</p>
<pre lang="php">// this action is executed just before the invocation of the WordPress authentication process
add_action('wp_authenticate','checkTheUserAuthentication');

function checkTheUserAuthentication() {

     $username=$_POST['log'];
     $password=$_POST['pwd'];

    // try to log into the external service or database with username and password
    $ext_auth = try2AuthenticateExternalService($username,$password);

    // if external authentication was successful
    if($ext_auth) {

         // find a way to get the user id
         $user_id = username_exists($username);
         // userdata will contain all information about the user
         $userdata = get_userdata($user_id);
         $user = set_current_user($user_id,$username);

         // this will actually make the user authenticated as soon as the cookie is in the browser
         wp_set_auth_cookie($user_id);
         // the wp_login action is used by a lot of plugins, just decide if you need it
        do_action('wp_login',$userdata->ID);

        // you can redirect the authenticated user to the "logged-in-page", define('MY_PROFILE_PAGE',1); f.e. first
        header("Location:".get_page_link(MY_PROFILE_PAGE));
    }

}</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Note that this script will login your useres totally <strong>without using their passwords</strong>, so use it carefully.</p>
<p>&nbsp;</p>
<p>If you experience any problems with this way of authentication, make sure that the Cookies in the Browser are set and sent properly &#8211; make sure that setcookie() in wp-includes/pluggable.php uses all parameters of the setcookie()-function correctly. Especially check the values for COOKIE_DOMAIN, COOKIEPATH and SITECOOKIEPATH as we had and issue with that.</p>
<p>&nbsp;</p>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2011%2F06%2F09%2Fwordpress-custom-external-authentication-loginlogout-php-script%2F&#038;title=WordPress%20custom%20external%20authentication%20login%2Flogout%20PHP%20script" data-a2a-url="https://blog.blackbam.at/2011/06/09/wordpress-custom-external-authentication-loginlogout-php-script/" data-a2a-title="WordPress custom external authentication login/logout PHP script"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2011/06/09/wordpress-custom-external-authentication-loginlogout-php-script/feed/</wfw:commentRss>
			<slash:comments>27</slash:comments>
		
		
			</item>
	</channel>
</rss>
