Source for file wpDirAuth.php
Documentation is available at wpDirAuth.php
* wpDirAuth: WordPress Directory Authentication (LDAP/LDAPS).
* Works with most LDAP enabled directory services, such as OpenLDAP,
* Apache Directory, Microsoft Active Directory, Novell eDirectory,
* Sun Java System Directory Server, etc.
* Please note that wpDirAuth will start in safe mode if it detects that
* another plugin is in conflict, by detecting if the wp_login and
* wp_setcookie functions have already been overwritten. It cannot,
* on the other hand, detect plugins that might want to overwrite these
* functions after wpDirAuth has been loaded.
* Originally forked from a patched version of wpLDAP.
* @see http://tekartist.org/labs/wordpress/plugins/wpdirauth/
* @license GPL <http://www.gnu.org/licenses/gpl.html>
* Copyrights are listed in chronological order, by contributions.
* wpDirAuth: WordPress Directory Authentication
* Copyright (c) 2007 Stephane Daury - http://stephane.daury.org/
* wpDirAuth and wpLDAP Patch Contributions
* Copyright (c) 2007 PKR Internet, LLC - http://www.pkrinternet.com/
* wpDirAuth Patch Contributions
* Copyright (c) 2007 Todd Beverly
* wpLDAP: WordPress LDAP Authentication
* Copyright (c) 2007 Ashay Suresh Manjure - http://ashay.org/
* wpDirAuth is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation.
* wpDirAuth is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
* @todo Always stay on top of security and user input validation while
* staying backwards compatible enough until PHP4 support is dropped in
* WP (serious patches welcomed, please see code). Note that we do
* heavily rely on WP's admin ACL scheme, by necessity.
PLUGIN META INFO FOR WORDPRESS LISTINGS
Plugin URI: http://tekartist.org/labs/wordpress/plugins/wpdirauth/
Description: WordPress Directory Authentication (LDAP/LDAPS).
Works with most LDAP enabled directory services, such as OpenLDAP,
Apache Directory, Microsoft Active Directory, Novell eDirectory,
Sun Java System Directory Server, etc.
Originally revived and upgraded from a patched version of wpLDAP.
Author: Stephane Daury [and whoever wants to help]
Author URI: http://stephane.daury.org/
define('WPDIRAUTH_VERSION', '1.0');
define('WPDIRAUTH_SIGNATURE', '<a href="http://tekartist.org/labs/wordpress/plugins/wpdirauth/">wpDirAuth</a> '.
WPDIRAUTH_VERSION);
* Default LDAP field to search against when locating the user's profile.
define('WPDIRAUTH_DEFAULT_FILTER', 'samAccountName');
* Default login screen message.
define('WPDIRAUTH_DEFAULT_LOGINSCREENMSG', '%s members can login directly using their institutional password.');
* Default password change message.
define('WPDIRAUTH_DEFAULT_CHANGEPASSMSG', 'To change a %s password, please refer to the official institutional password policy.');
* Allowed HTML (messages)
define('WPDIRAUTH_ALLOWED_TAGS', '<a><strong><em><p><ul><ol><li>');
* SAFE MODE: wpDirAuth plugin configuration panel.
* Processes and outputs the wpDirAuth configuration form, with a conflict message.
$message = <<<________EOS
<
h3>
Sorry,
but your PHP install does not seem to have access to the LDAP features.</
h3>
<
br />
wpDirAuth is now running in safe mode.'
Quote from the <
a href="
http://
php.
net/
ldap#
ldap.
installation">
PHP manual LDAP section</
a>:
LDAP support in PHP is not enabled by default.
You will need to use the
--
with-
ldap[=
DIR] configuration option when compiling PHP to enable LDAP
support.
DIR is the LDAP base install directory.
To enable SASL support,
be sure --
with-
ldap-
sasl[=
DIR] is used,
and that sasl.
h exists on the system.
$message = <<<________EOS
<
h3>
Sorry,
but another plugin seems to be conflicting with wpDirAuth.</
h3>
<
br />
wpDirAuth is now running in safe mode as to not impair the other plugin'
s operations.'
The wp_login and wp_setcookie WordPress
<
a href="
http://
codex.
wordpress.
org/
Pluggable_Functions">
pluggable functions</
a>
have already been redefined,
and wpDirAuth cannot provide directory authentication
without having access to these functions.
Please disable any WP plugins that deal with authentication in order to use wpDirAuth.
Unfortunately,
we cannot provide you with more info as to which plugin is in conflict.
<
h2>
Directory Authentication Options:
Plugin Conflict</
h2>
* SAFE MODE: Adds the `Directory Auth.` menu entry in the Wordpress Admin section.
* Also activates the wpDirAuth config panel, with a conflict message, as a callback function.
* @uses wpDirAuth_safeConflictMessage
'Directory Authentication Options: Plugin Conflict',
'wpDirAuth_safeConflictMessage'
* SAFE MODE: Add custom WordPress actions.
* @uses wpDirAuth_safeAddMenu
add_action('admin_menu', 'wpDirAuth_safeAddMenu');
* Generates a random string to be used as salt for the password
* hash cookie checks in wp_setcookie and wp_login
* @return string 55 chars-long salty goodness (md5 + uniqid)
$_SERVER['SERVER_SIGNATURE']
.
$_SERVER['HTTP_USER_AGENT']
update_option("dirAuthCookieMarker",$cookieMarker);
* Tries two different documented method of php-based ldap binding.
* Note: passing params by reference, no need for copies (unlike in
* wpDirAuth_auth where it is desirable).
* @param object &$connection LDAP connection
* @param string &$username LDAP username
* @param string &$password LDAP password
* @return boolean Binding status
if ( ($isBound =
@ldap_bind($connection, $username, $password)) ===
false ) {
// @see wpLDAP comment at http://ashay.org/?page_id=133#comment-558
$isBound =
@ldap_bind($connection,"uid=$username,$baseDn", $password);
* Custom LDAP authentication module.
* The returned keys are in the same format used by WP for
* the wp_insert_user and wp_update_user functions.
* @param string $username LDAP username
* @param string $password LDAP password
* @return boolean false OR array Directory email, last_name and first_name
* @uses WPDIRAUTH_DEFAULT_FILTER
* @uses wpDirAuth_bindTest
$errorTitle =
'<strong>'.
__('Directory Login Error').
'</strong>: ';
$controllers =
explode(',', get_option('dirAuthControllers'));
$baseDn =
get_option('dirAuthBaseDn');
$accountSuffix =
get_option('dirAuthAccountSuffix');
$filter =
get_option('dirAuthFilter');
$enableSsl =
get_option('dirAuthEnableSsl');
$returnKeys =
array('sn', 'givenname', 'mail');
$isBound =
$isLoggedIn =
false;
if (count($controllers) >
1) {
// shuffle the domain controllers for pseudo load balancing and fault tolerance.
elseif (count($controllers) ==
0) {
.
__(' wpDirAuth config error: no domain controllers specified.');
if ($accountSuffix) $username .=
$accountSuffix;
$protocol =
($enableSsl) ?
'ldaps' :
'ldap';
$filterQuery =
"($filter=$username)";
// Connection pool loop - Haha, PooL LooP
foreach ($controllers as $dc) {
* The lack of conditional check at the ldap_connect() level below
* is because with php and openldap 2.x, the ldap_connect() will
* always return a resource as it does not actually connect but just
* initializes the connecting parameters. The actual connection happens
* with the following ldap_bind() which is itself wrapped in a
* @see Notes at http://php.net/ldap_connect
* Copes with W2K3/AD issue.
* @see http://bugs.php.net/bug.php?id=30670
* Attempt bind, both anonymously or with credentials (see cases)
* Use case 1: Servers that will not let you bind anonymously
* @see http://groups.google.com/group/wpdirauth-support/browse_thread/thread/8fd16c05266fc832
* @see wpDirAuth_bindTest
elseif ( ($isBound =
@ldap_bind($connection)) ===
true ) {
* Use case 2: Servers that might require a full user DN to
* actually login and therefore let you bind anonymously first .
* Try ldap_search + ldap_get_dn before attempting a login.
* @see http://wordpress.org/support/topic/129814?replies=34#post-603644
if ( ($results =
@ldap_search($connection, $baseDn, $filterQuery, $returnKeys)) !==
false ) {
.
__(' No directory server available for authentication.');
elseif ( ($isLoggedIn ===
false) &&
( ($isBound =
wpDirAuth_bindTest($connection, $username, $password)) ===
false ) ) {
.
__(' Could not authenticate user. Please check your credentials.')
* Search for profile, if still needed.
* @see Preceding loop: Use case 1 with anonymous ldap_search
* failure or use case 2 and 3 in loop above)
if (!$results) $results =
@ldap_search($connection, $baseDn, $filterQuery, $returnKeys);
.
__('Directory authentication initially succeeded, but no
valid profile was found (search procedure).')
$count =
intval($userInfo['count']);
.
__('Directory authentication initially succeeded, but no
valid profile was found ("get entries" procedure).')
.
__('Directory authentication initially succeeded, but the
username you sent is not a unique profile identifier.')
$email = isset
($userInfo[0]['mail'][0])
?
$userInfo[0]['mail'][0] :
'';
$lastName = isset
($userInfo[0]['sn'][0])
?
$userInfo[0]['sn'][0] :
'';
$firstName = isset
($userInfo[0]['givenname'][0])
?
$userInfo[0]['givenname'][0] :
'';
'last_name' =>
$lastName,
'first_name' =>
$firstName
* Runs stripslashes, html_entity_decode, then strip_tags with
* allowed html if requested.
* No input sashimi for us (hopefully).
* @param string $value Value to `sanitize`
* @param boolean $allowed Set to true for WPDIRAUTH_ALLOWED_TAGS
* @return string Cleaner value.
* @uses WPDIRAUTH_ALLOWED_TAGS
* wpDirAuth plugin configuration panel.
* Processes and outputs the wpDirAuth configuration form.
* @uses WPDIRAUTH_DEFAULT_FILTER
* @uses WPDIRAUTH_DEFAULT_LOGINSCREENMSG
* @uses WPDIRAUTH_DEFAULT_CHANGEPASSMSG
* @uses WPDIRAUTH_ALLOWED_TAGS
* @uses wpDirAuth_makeCookieMarker
* @uses wpDirAuth_sanitize
$curUserIsDirUser =
get_usermeta($userdata->ID, 'wpDirAuthFlag');
<
h2>
Directory Authentication Options</
h2>
Because any changes made to directory authentication
options can adversly affect your session when logged in
as a directory user,
you must be logged in as a
WordPress-
only administrator user to update these settings.
If such a user no longer exists in the database,
please
<
a href="./
users.
php#
add-
new-
user">
create a new one</
a>
using the appropriate WordPress admin tool.
$enable =
intval($_POST['dirAuthEnable']) ==
1 ?
1 :
0;
$enableSsl =
intval($_POST['dirAuthEnableSsl']) ==
1 ?
1 :
0;
$requireSsl =
intval($_POST['dirAuthRequireSsl']) ==
1 ?
1 :
0;
$TOS =
intval($_POST['dirAuthTOS']) ==
1 ?
1 :
0;
// Have to be allowed to contain some HTML
update_option('dirAuthEnable', $enable);
update_option('dirAuthEnableSsl', $enableSsl);
update_option('dirAuthRequireSsl', $requireSsl);
update_option('dirAuthControllers', $controllers);
update_option('dirAuthBaseDn', $baseDn);
update_option('dirAuthAccountSuffix', $accountSuffix);
update_option('dirAuthFilter', $filter);
update_option('dirAuthInstitution', $institution);
update_option('dirAuthLoginScreenMsg', $loginScreenMsg);
update_option('dirAuthChangePassMsg', $changePassMsg);
update_option('dirAuthTOS', $TOS);
if (get_option('dirAuthEnable') &&
!get_option('dirAuthCookieMarker')) {
echo
'<div id="message" class="updated fade"><p>Your new settings were saved successfully.</p></div>';
$enable =
intval(get_option('dirAuthEnable')) ==
1 ?
1 :
0;
$enableSsl =
intval(get_option('dirAuthEnableSsl')) ==
1 ?
1 :
0;
$requireSsl =
intval(get_option('dirAuthRequireSsl')) ==
1 ?
1 :
0;
$TOS =
intval(get_option('dirAuthTOS')) ==
1 ?
1 :
0;
// Have to be allowed to contain some HTML
$filter =
$defaultFilter;
<
h2>
Directory Authentication Options</
h2>
<
form method="
post"
id="
dir_auth_options">
<
fieldset class="
options">
<
p class="
submit"><
input type="
submit"
name="
dirAuthOptionsSave"
value="
Update Options &
raquo;" /></
p>
<
fieldset class="
options">
<
legend>
WordPress Settings</
legend>
<
label for="
dirAuthEnable"><
strong>
Enable Directory Authentication?</
strong></
label>
<
input type="
radio"
name="
dirAuthEnable"
value="1"
$tEnable />
Yes &
nbsp;
<
input type="
radio"
name="
dirAuthEnable"
value="0"
$fEnable />
No
<
strong>
NOTE</
strong>:
Users created in WordPress are not affected by your directory authentication settings.
<
label for="
dirAuthRequireSsl"><
strong>
Require SSL Login?</
strong></
label>
<
input type="
radio"
name="
dirAuthRequireSsl"
value="1"
$tWpSsl/>
Yes &
nbsp;
<
input type="
radio"
name="
dirAuthRequireSsl"
value="0"
$fWpSsl/>
No
<
em>
Force the WordPress login screen to require encryption (
SSL,
https://
URL)?</
em>
<
fieldset class="
options">
<
legend>
Directory Settings</
legend>
<
label for="
dirAuthEnableSsl"><
strong>
Enable SSL Connectivity?</
strong></
label>
<
input type="
radio"
name="
dirAuthEnableSsl"
value="1"
$tSsl/>
Yes &
nbsp;
<
input type="
radio"
name="
dirAuthEnableSsl"
value="0"
$fSsl/>
No
<
em>
Use encryption (
SSL,
ldaps://
URL)
when WordPress connects to the directory server(
s)?</
em>
<
label for="
dirAuthControllers"><
strong>
Directory Servers (
Domain Controllers)</
strong></
label>
<
input type="
text"
name="
dirAuthControllers"
value="
$controllers"
size="40"/><
br />
<
em>
The DNS name or IP address of the directory server(
s).
Separate multiple entries by a comma (,).</
em>
<
label for="
dirAuthBaseDn"><
strong>
Base DN</
strong></
label>
<
input type="
text"
name="
dirAuthBaseDn"
value="
$baseDn"
size="40"/><
br />
<
em>
The base DN for carrying out LDAP searches.</
em>
<
label for="
dirAuthAccountSuffix"><
strong>
Account Suffix</
strong></
label>
<
input type="
text"
name="
dirAuthAccountSuffix"
value="
$accountSuffix"
size="40" /><
br />
Suffix needed to be appended to the username.
e.
g. @
domain.
com<
br />
<
strong>
NOTE:</
strong>
Changing this value will cause your existing directory users to have new accounts created the next time they login.
<
label for="
dirAuthFilter"><
strong>
Account Filter</
strong></
label>
<
input type="
text"
name="
dirAuthFilter"
value="
$filter"
size="40"/>
(
Defaults to <
em>
$defaultFilter</
em>)
<
em>
What LDAP field should we search the username against to locate the user'
s profile after successful login?</
em>
<
fieldset class="
options">
<
legend>
Branding Settings</
legend>
<
label for="
dirAuthInstitution"><
strong>
Institution Name</
strong></
label>
<
input type="
text"
name="
dirAuthInstitution"
value="
$institution"
size="40" />
<
em>
Name of your institution/
company.
Displayed on the login screen.</
em>
<
label for="
dirAuthLoginScreenMsg"><
strong>
Login Screen Message</
strong></
label>
<
textarea name="
dirAuthLoginScreenMsg"
cols="40"
rows="3">
$loginScreenMsg</
textarea>
Displayed on the login screen,
underneath the username/
password fields.<
br />
Some HTML allowed:
$allowedHTML
<
label for="
dirAuthChangePassMsg"><
strong>
Password Change Message</
strong></
label>
<
textarea name="
dirAuthChangePassMsg"
cols="40"
rows="3">
$changePassMsg</
textarea>
Displayed wherever user passwords can be changed,
for directory users only.<
br />
Some HTML allowed:
$allowedHTML
<
label for="
dirAuthTOS"><
strong>
Terms of Services Agreement</
strong></
label>
<
input type="
radio"
name="
dirAuthTOS"
value="1"
$tTOS/>
Yes &
nbsp;
<
input type="
radio"
name="
dirAuthTOS"
value="0"
$fTOS/>
No
Ask directory users to agree to terms of services that you link to in the message above?<
br />
<
strong>
Note</
strong>:
Checkbox disappears once checked,
date of agreement is stored and users are no longer prompted.
<
p class="
submit"><
input type="
submit"
name="
dirAuthOptionsSave"
value="
Update Options &
raquo;" /></
p>
<
p>
Powered by $wpDARef.</
p>
* Adds the `Directory Auth.` menu entry in the Wordpress Admin section.
* Also activates the wpDirAuth config panel as a callback function.
* @uses wpDirAuth_optionsPanel
'Directory Authentication Options',
* Extending WP's login_form.
* Enforces the admin defined SSL login preferences and adds a directory
* login related message to the standard WP login screen.
* @uses WPDIRAUTH_DEFAULT_LOGINSCREENMSG
if (get_option('dirAuthEnable')) {
if (isset
($_SERVER['SCRIPT_URI']) &&
preg_match('|^http|',$_SERVER['SCRIPT_URI'])) {
$selfURL =
$_SERVER['SCRIPT_URI'];
* $_SERVER['SCRIPT_URI'] seems to be unavilable in some PHP
* installs, and $_SERVER['REQUEST_URI'] and $_SERVER['PHP_SELF']
* have been known to sometimes have the same issue.
* Thanks to Todd Beverly for helping out with this one. :)
* @see http://wordpress.org/support/topic/129814?replies=27#post-605423
(isset
($_SERVER['HTTPS']) &&
$_SERVER['HTTPS'] ==
'on' ?
's' :
''),
(isset
($_SERVER['REQUEST_URI'])
?
$_SERVER['REQUEST_URI']
:
$_SERVER["SCRIPT_NAME"].
'?'.
$_SERVER['QUERY_STRING'])
if (get_option('dirAuthRequireSsl') &&
(!preg_match('|^https|',$selfURL))) {
$refreshJS =
'<script type="text/javascript">'.
"\n".
'top.location.href=\''.
$location.
'\';'.
"\n".
'</script>" />';
$refreshMeta =
'<meta http-equiv="refresh" content="0;url='.
$location.
'" />';
$refreshMsg =
'Please access the <a href="'.
$location.
'">encrypted version</a> of this page.';
echo
$refreshJS.
$refreshMeta.
'<p>'.
$refreshMsg.
'</p></form></div></html>';
$location =
str_replace('http://','https://',$selfURL);
if (!@header('Location:'.
$location)) {
echo
'<html><head>'.
$refreshJS.
$refreshMeta.
'</head>'
.
'<body>'.
$refreshMsg.
'</body></html>';
$dirAuthInstitution =
stripslashes(get_option('dirAuthInstitution'));
if (!$dirAuthInstitution) $dirAuthInstitution =
__('Directory');
$loginScreenMsg =
stripslashes(get_option('dirAuthLoginScreenMsg'));
if (!$loginScreenMsg) $loginScreenMsg =
__(sprintf(
get_option('dirAuthInstitution')
<style>.wpDirAuthMsg a, .wpDirAuthMsg a:visited {color: #ebcd4e;}</style>
<p class="wpDirAuthMsg">'.
$loginScreenMsg.
'</p>
* Extending WP's show_password_fields.
* Displays the directory password change message in profile.php and user.php.
* @return boolean Return format as expected by WP's show_password_fields()
* @uses WPDIRAUTH_DEFAULT_CHANGEPASSMSG
global $profileuser, $userdata;
$editUserIsDirUser =
get_usermeta($profileuser->ID, 'wpDirAuthFlag');
if (!$editUserIsDirUser) {
// Editing directory user profile, show password msg
$message =
stripslashes(get_option('dirAuthChangePassMsg'));
if (get_option('dirAuthTOS')) {
if (($TOSDate =
get_usermeta($profileuser->ID, 'wpDirAuthTOS')) ===
'') {
if ($userdata->ID ==
$profileuser->ID) {
// Only show TOS acceptance checkbox to the owner of the profile.
$message .=
'</p><p class="desc">'
.
'<input type="checkbox" name="wpDirAuthTOS" value="1" style="width:15px; height:15px;" /> '
.
__('Accept terms of services.')
.
'</p><p class="desc">';
// Show generic message to other admins.
$message .=
'</p><p class="desc">'
.
__('User has not yet agreed to the terms of services.')
.
'</p><p class="desc">';
// Show TOS acceptance date
$message .=
'</p><p class="desc">'
.
__('Terms of services accepted on')
.
'</p><p class="desc">';
echo
'<fieldset><legend>'
.
__('Directory Password Update')
.
'</legend><p class="desc">'
* Extending WP's profile_update.
* Saves the TOS acceptance if sent.
* @param integer $userID Sent by WP profile_update action
* @return boolean Return format as expected by WP's profile_update()
if (intval($_POST['wpDirAuthTOS']) ===
1) {
update_usermeta($userID, 'wpDirAuthTOS', date('Y-m-d H:i:s'));
* WP's wp_login overwrite.
* Processes the directory login and creates a new user on first access.
* @param string $username Login form username.
* @param string $password Login form password
* @param boolean $already_md5 Has the pswd been double-hashed already?
* @uses wpDirAuth_makeCookieMarker
* @see http://codex.wordpress.org/Pluggable_Functions
function wp_login($username, $password, $already_md5 =
false)
$error =
__('<strong>Login Error</strong>:
The password field is empty.');
$enable =
get_option('dirAuthEnable');
$cookieMarker =
get_option('dirAuthCookieMarker');
* Get the login object. We will use it for first user insertion or when the
* directory auth option is not activated.
$login =
get_userdatabylogin($username);
$loginUserIsDirUser =
($login) ?
get_usermeta($login->ID, 'wpDirAuthFlag') :
0;
if (!$enable &&
$loginUserIsDirUser) {
* Existing directory user, but directory access has now been disabled.
$error =
__('<strong>Directory Login Error</strong>:
Sorry, but the site administrators have disabled
directory access in this WordPress install.');
* If already_md5 is TRUE, then we're getting the user/password from the cookie.
* As we don't want to store LDAP passwords in any form, we've already replaced
* the password with the hashed username and dirAuthCookieMarker
if ($password ==
md5($username).
md5($cookieMarker)) {
* No existing account record found, try dir auth
if ($userData !==
false) {
* Passed directory signin, so create a new WP user
require_once(ABSPATH .
WPINC .
'/registration.php');
$userLogin =
sanitize_user($username);
$userEmail =
apply_filters('user_registration_email', $userData['email']);
if (username_exists($userLogin)) {
$error =
__('<strong>Directory Login Error</strong>:
Could not create a new WP user account
because your directory username is already
registered on this site.')
elseif (email_exists($userLogin)) {
$error =
__('<strong>Directory Login Error</strong>:
Could not create a new WP account because
the email retrieved from the directory is
already registered with this site.')
elseif ($userID =
wp_create_user($userLogin, $password, $userEmail)) {
$userData['ID'] =
$userID;
$tmpAr =
split('@',$userData['email']);
$userData['nickname'] =
str_replace('.','_',$tmpAr[0]);
$userData['display_name'] =
$userData['first_name'].
' '.
$userData['last_name'];
unset
($userData['email']);
wp_update_user($userData);
update_usermeta($userID, 'wpDirAuthFlag', 1);
$error =
__('<strong>Directory Login Error</strong>:
Could not create a new user account.
.
" [user: $userLogin, email: $userEmail]";
* Did not pass dir auth, and no login present in WP
if (!$error) $error =
__('<strong>Login Error</strong>:
Could not authenticate user in
either WordPress or the directory.
Please check credentials.');
* Dealing with an existing WP account
if (!$loginUserIsDirUser) {
* If the password is already_md5, it has been double hashed.
* Otherwise, it is plain text.
if ( ($already_md5 &&
$login->user_login ==
$username &&
md5($login->user_pass) ==
$password)
||
($login->user_login ==
$username &&
$login->user_pass ==
md5($password)) ) {
* WP user, password okay.
$error =
__('<strong>WordPress Login Error</strong>:
* Directory user, try ldap binding
if ($userData !==
false) {
* Directory user, password okay.
* Directory user, wrong pass
$error =
__('<strong>Directory Login Error</strong>:
* Directory auth == false
* No existing account record found
$error =
__('<strong>WordPress Login Error</strong>:
Could not authenticate user.
Please check your credentials.');
* Found an existing WP account.
* If the password is already_md5, it has been double hashed.
* Otherwise, it is plain text.
if ( ($already_md5 &&
$login->user_login ==
$username &&
md5($login->user_pass) ==
$password)
||
($login->user_login ==
$username &&
$login->user_pass ==
md5($password)) ) {
* WP user, password okay.
$error =
__('<strong>WordPress Login Error</strong>:
* WordPress wp_setcookie overwrite.
* Sets the WP session cookies.
* @param string $username Login form username.
* @param string $password Login form password
* @param boolean $already_md5 Has the pswd been double-hashed already?
* @param boolean $remember
* @uses wpDirAuth_makeCookieMarker
* @see http://codex.wordpress.org/Pluggable_Functions
function wp_setcookie($username, $password, $already_md5 =
false, $home =
'', $siteurl =
'', $remember =
false)
* Try to locate the user's record and define if it is an existing directory user
$login =
get_userdatabylogin($username);
//$login = $wpdb->get_row('SELECT ID FROM $wpdb->users WHERE user_login = '$username'');
$loginUserIsDirUser =
($login) ?
get_usermeta($login->ID, 'wpDirAuthFlag') :
0;
$enable =
get_option('dirAuthEnable');
$cookieMarker =
get_option('dirAuthCookieMarker');
* Set the password hash cookie
if (($enable) &&
($loginUserIsDirUser)) {
$password =
md5($username).
md5($cookieMarker);
$password =
md5( md5($password) ); // Double hash the password in the cookie.
* Updated WP remember me option for directory users to only be
* remembered for 1 hour so that institutional passwords are not
* overly endangered when accessing the blog from a public terminal.
$expire =
time() +
$duration;
* The rest of the logic is from the original WP wp_setcookie
* function, from /wp-inlcudes/pluggable.php version 2.2.2
$cookiepath =
COOKIEPATH;
$cookiepath =
preg_replace('|https?://[^/]+|i', '', $home .
'/' );
$sitecookiepath =
SITECOOKIEPATH;
$cookiehash =
COOKIEHASH;
$sitecookiepath =
preg_replace('|https?://[^/]+|i', '', $siteurl .
'/' );
$cookiehash =
md5($siteurl);
setcookie(USER_COOKIE, $username, $expire, $cookiepath, COOKIE_DOMAIN);
setcookie(PASS_COOKIE, $password, $expire, $cookiepath, COOKIE_DOMAIN);
if ( $cookiepath !=
$sitecookiepath ) {
setcookie(USER_COOKIE, $username, $expire, $sitecookiepath, COOKIE_DOMAIN);
setcookie(PASS_COOKIE, $password, $expire, $sitecookiepath, COOKIE_DOMAIN);
* Add custom WordPress actions
* @uses wpDirAuth_addMenu
* @uses wpDirAuth_loginFormExtra
add_action('admin_menu', 'wpDirAuth_addMenu');
add_action('login_form', 'wpDirAuth_loginFormExtra');
add_action('user_register', 'wpDirAuth_profileFormExtra');
add_action('profile_update', 'wpDirAuth_profileUpdate');
* Add custom WordPress filters
* @uses wpDirAuth_hidePassFields
add_filter('show_password_fields', 'wpDirAuth_hidePassFields');
Documentation generated on Fri, 31 Aug 2007 21:41:27 -0400 by phpDocumentor 1.4.0a2