- if (password_check($password, $password2) !== true) {
- continue;
- }
- // support pre hashed passwords
- if (preg_match('/^{(ARGON2I|ARGON2ID|BLF-CRYPT|CLEAR|CLEARTEXT|CRYPT|DES-CRYPT|LDAP-MD5|MD5|MD5-CRYPT|PBKDF2|PLAIN|PLAIN-MD4|PLAIN-MD5|PLAIN-TRUNC|PLAIN-TRUNC|SHA|SHA1|SHA256|SHA256-CRYPT|SHA512|SHA512-CRYPT|SMD5|SSHA|SSHA256|SSHA512)}/i', $password)) {
- $password_hashed = $password;
- }
- else {
- $password_hashed = hash_password($password);
+ if (!empty($password)) {
+ if (password_check($password, $password2) !== true) {
+ continue;
+ }
+ // support pre hashed passwords
+ if (preg_match('/^{(ARGON2I|ARGON2ID|BLF-CRYPT|CLEAR|CLEARTEXT|CRYPT|DES-CRYPT|LDAP-MD5|MD5|MD5-CRYPT|PBKDF2|PLAIN|PLAIN-MD4|PLAIN-MD5|PLAIN-TRUNC|PLAIN-TRUNC|SHA|SHA1|SHA256|SHA256-CRYPT|SHA512|SHA512-CRYPT|SMD5|SSHA|SSHA256|SSHA512)}/i', $password)) {
+ $password_hashed = $password;
+ }
+ else {
+ $password_hashed = hash_password($password);
+ }
+ $stmt = $pdo->prepare("UPDATE `mailbox` SET
+ `password` = :password_hashed
+ WHERE `username` = :username");
+ $stmt->execute(array(
+ ':password_hashed' => $password_hashed,
+ ':username' => $username
+ ));
}
}
- $stmt = $pdo->prepare("UPDATE `mailbox` SET
- `password` = :password_hashed
- WHERE `username` = :username");
- $stmt->execute(array(
- ':password_hashed' => $password_hashed,
- ':username' => $username
- ));
// We could either set alias = 1 if alias = 2 or tune the Postfix alias table (that's what we did, TODO: to it the other way)
// We could either set alias = 1 if alias = 2 or tune the Postfix alias table (that's what we did, TODO: to it the other way)
+Adldap2 is a PHP LDAP package that allows you to:
+
+1. Easily manage multiple LDAP connections at once
+2. Perform authentication
+3. Search your LDAP directory with a fluent and easy to use query builder
+4. Create / Update / Delete LDAP entities with ease
+5. And more
+
+## History of Adldap2
+
+Adldap2 was originally created as a fork of the original LDAP library [adLDAP](https://github.com/adldap/adLDAP) due to bugs, and it being completely abandoned.
+
+Adldap2 contains absolutely no similarities to the original repository, and was built to be as easily accessible as possible, with great documentation, and easily understandable syntax.
+
+Much of the API was constructed with Ruby's ActiveRecord and Laravel's Eloquent in mind, and to be an answer to the question:
+
+> _Why can't we use LDAP like we use a database?_
+
+## Why should you use Adldap2?
+
+Working with LDAP in PHP can be a messy and confusing endeavor, especially when using multiple connections, creating and managing entities, performing moves, resetting passwords, and performing ACL modifications to user accounts.
+
+Wrapper classes for LDAP are usually always created in PHP applications.
+
+Adldap2 allows you to easily manage the above problems without reinventing the wheel for every project.
+The port option is used for authenticating and binding to your LDAP server.
+
+The default ports are already used for non SSL and SSL connections (389 and 636).
+
+Only insert a port if your LDAP server uses a unique port.
+
+##### Follow Referrals
+
+The follow referrals option is a boolean to tell active directory to follow a referral to another server on your network if the server queried knows the information your asking for exists, but does not yet contain a copy of it locally.
+
+This option is defaulted to false.
+
+Disable this option if you're experiencing search / connectivity issues.
+
+For more information, visit: https://technet.microsoft.com/en-us/library/cc978014.aspx
+
+##### SSL & TLS
+
+These Boolean options enable an SSL or TLS connection to your LDAP server.
+
+Only **one** can be set to `true`. You must chose either or.
+
+> **Note**: You **must** enable SSL or TLS to reset passwords in ActiveDirectory.
+
+These options are definitely recommended if you have the ability to connect to your server securely.
+
+> **Note**: TLS is recommended over SSL, as SSL is now labelled as a depreciated mechanism for securely running LDAP operations.
+
+##### Version
+
+The LDAP version to use for your connection.
+
+Must be an integer and can either be `2` or `3`.
+
+##### Timeout
+
+The timeout option allows you to configure the amount of seconds to wait until
+your application receives a response from your LDAP server.
+
+The default is 5 seconds.
+
+##### Custom Options
+
+Arbitrary options can be set for the connection to fine-tune TLS and connection behavior.
+
+Please note that `LDAP_OPT_PROTOCOL_VERSION`, `LDAP_OPT_NETWORK_TIMEOUT` and `LDAP_OPT_REFERRALS` will be ignored if set.
+
+These are set above with the `version`, `timeout` and `follow_referrals` keys respectively.
+
+Valid options are listed in the [PHP documentation for ldap_set_option](http://php.net/ldap_set_option).
+
+## Getting Started
+
+Each LDAP connection you have will be contained inside the `Adldap` instance as its own **connection provider**.
+
+There are a couple of ways you can easily add each of your LDAP connections. Let's walk through them:
+
+**Using a configuration array:**
+```php
+$config = ['...'];
+
+$ad = new Adldap\Adldap();
+
+$ad->addProvider($config);
+
+// You can also specify the name of the
+// connection as the second argument:
+$ad->addProvider($config, 'connection-one');
+```
+
+**Using a DomainConfiguration object:**
+```php
+$ad = new Adldap\Adldap();
+
+$config = new Adldap\Configuration\DomainConfiguration(['...']);
+
+$ad->addProvider($config, 'connection-one');
+```
+
+**Using the constructor:**
+
+> **Note**: When inserting your configuration into a new `Adldap` instance, you
+> need to set a key for each connection. **This will be its connection name**.
+
+```php
+$connections = [
+ 'connection1' => [
+ 'hosts' => ['...'],
+ ],
+ 'connection2' => [
+ 'hosts' => ['...'],
+ ],
+];
+
+$ad = new Adldap\Adldap($connections);
+```
+
+## Connecting
+
+The easiest way to get connected is to call the `connect($name)` method on your `Adldap` instance.
+
+Its first argument accepts the name of your configured connection.
+
+This method will return you a connected **connection provider** when
+successful, and throw an exception when unsuccessful:
+
+```php
+$ad = new Adldap\Adldap();
+
+$config = ['...'];
+
+$connectionName = 'my-connection';
+
+$ad->addProvider($config, $connectionName);
+
+try {
+ $provider = $ad->connect($connectionName);
+
+ // Great, we're connected!
+} catch (Adldap\Auth\BindException $e) {
+ // Failed to connect.
+}
+```
+
+### Using an alternate username / password
+
+If you'd like to connect to your configured connection using a different username and password than your configuration, then simply provide them in the second and third arguments:
+Now that you've learned the basics of configuration and
+getting yourself connected, continue on to learn
+[how to search your LDAP directory](searching.md).
+
+## Using Other LDAP Servers (OpenLDAP / FreeIPA / etc.)
+
+Alternate LDAP server variants such as OpenLDAP or FreeIPA contain
+some different attribute names than ActiveDirectory.
+
+The Adldap2 schema offers an attribute map for each available LDAP attribute, and
+is completely configurable and customizable.
+
+If you're using an alternate LDAP server variant such as OpenLDAP or FreeIPA, you **must** change the default schema inside your configuration array. If you do not, you won't receive the correct model instances for results, and you won't be
+able to utilize some standard methods available on these models.
+
+By default, Adldap2 is configured to be used with **Microsoft ActiveDirectory**.
+
+When creating your configuration array, set your schema using the `schema` key:
+
+
+**Using configuration array:**
+```php
+$ad = new Adldap\Adldap();
+
+$config = [
+ '...',
+ 'schema' => Adldap\Schemas\OpenLDAP::class
+];
+
+$ad->addProvider($config);
+```
+
+**Using configuration object:**
+```php
+$ad = new Adldap\Adldap();
+
+$config = new Adldap\Configuration\DomainConfiguration();
+If you want to connect to your LDAP server without utilizing Adldap's models (old fashion way), and want to get back the data in a raw format you can easily do so.
+
+If you call `getConnection()` on your connected provider instance, you can perform all LDAP functions on a container class that encapsulates all of PHP's LDAP methods.
+
+You can view all methods avaialble by browsing the LDAP class [here](https://github.com/Adldap2/Adldap2/blob/master/src/Connections/Ldap.php).
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Adldap2 is a PHP package that provides LDAP authentication and directory management tools using the <a href="https://en.wikipedia.org/wiki/Active_record_pattern">Active Record pattern</a>.
+- **Up and running in minutes.** Effortlessly connect to your LDAP servers and start running queries & operations in a matter of minutes.
+
+- **Fluent query builder.** Building LDAP queries has never been so easy. Find the records you're looking for in a couple lines or less with a fluent interface.
+
+- **Supercharged Active Record.** Create and modify LDAP records with ease. All LDAP records are individual models. Simply modify the attributes on the model and save it to persist the changes to your LDAP server.