title: How do I change AD user password by using Adldap2-laravel package?
body: <p>I would like to change the password of a user in AD since there are no attribute for password in AD.</p>
  
  <p>Currently running laravel framework with Adldap2-laravel package in order to manage ADLDAP operations.</p>
  
  <p>Here's my ldap_auth.php</p>
  
  <pre><code>&lt;?php
  
  return [
      'connection' =&gt; env('LDAP_CONNECTION', 'default'),
      'provider' =&gt; Adldap\Laravel\Auth\DatabaseUserProvider::class,
      'model' =&gt; App\User::class,
      'rules' =&gt; [
          Adldap\Laravel\Validation\Rules\DenyTrashed::class,
      ],
      'scopes' =&gt; [
          Adldap\Laravel\Scopes\UidScope::class
      ],
      'identifiers' =&gt; [
          'ldap' =&gt; [
              'locate_users_by' =&gt; 'uid',
              'bind_users_by' =&gt; 'dn',
          ],
          'database' =&gt; [
              'guid_column' =&gt; 'objectguid',
              'username_column' =&gt; 'username',
          ],
          'windows' =&gt; [
              'locate_users_by' =&gt; 'samaccountname',
              'server_key' =&gt; 'AUTH_USER',
          ],
      ],
      'passwords' =&gt; [
          'sync' =&gt; env('LDAP_PASSWORD_SYNC', false),
          'column' =&gt; 'password',
      ],
      'login_fallback' =&gt; env('LDAP_LOGIN_FALLBACK', false),
      'sync_attributes' =&gt; [
          'username' =&gt; 'uid',
          'password' =&gt; 'userPassword',
          'name' =&gt; 'cn',
          'role' =&gt; 'l',
          'category' =&gt; 'businessCategory',
          'telephone_number' =&gt; 'telephoneNumber',
          'email' =&gt; 'mail'
  
      ],
      'logging' =&gt; [
  
          'enabled' =&gt; env('LDAP_LOGGING', true),
  
          'events' =&gt; [
  
              \Adldap\Laravel\Events\Importing::class                 =&gt; \Adldap\Laravel\Listeners\LogImport::class,
              \Adldap\Laravel\Events\Synchronized::class              =&gt; \Adldap\Laravel\Listeners\LogSynchronized::class,
              \Adldap\Laravel\Events\Synchronizing::class             =&gt; \Adldap\Laravel\Listeners\LogSynchronizing::class,
              \Adldap\Laravel\Events\Authenticated::class             =&gt; \Adldap\Laravel\Listeners\LogAuthenticated::class,
              \Adldap\Laravel\Events\Authenticating::class            =&gt; \Adldap\Laravel\Listeners\LogAuthentication::class,
              \Adldap\Laravel\Events\AuthenticationFailed::class      =&gt; \Adldap\Laravel\Listeners\LogAuthenticationFailure::class,
              \Adldap\Laravel\Events\AuthenticationRejected::class    =&gt; \Adldap\Laravel\Listeners\LogAuthenticationRejection::class,
              \Adldap\Laravel\Events\AuthenticationSuccessful::class  =&gt; \Adldap\Laravel\Listeners\LogAuthenticationSuccess::class,
              \Adldap\Laravel\Events\DiscoveredWithCredentials::class =&gt; \Adldap\Laravel\Listeners\LogDiscovery::class,
              \Adldap\Laravel\Events\AuthenticatedWithWindows::class  =&gt; \Adldap\Laravel\Listeners\LogWindowsAuth::class,
              \Adldap\Laravel\Events\AuthenticatedModelTrashed::class =&gt; \Adldap\Laravel\Listeners\LogTrashedModel::class,
  
          ],
      ],
  
  ];
  </code></pre>
  
  <p>Here is my LdapController.php where I include function to reset password</p>
  
  <pre><code>public function resetPassword(Request $req)
      {
          $req-&gt;validate([
              'userid' =&gt; 'required',
              'password' =&gt; 'required|min:6|confirmed'
          ]);
          $userLdap = Adldap::search()-&gt;where('uid', $req-&gt;userid)-&gt;firstOrFail();
          $newPassword = "{SHA}" . base64_encode(pack("H*", sha1($req-&gt;password)));
          $res = $userLdap-&gt;update([
              'userpassword' =&gt; $newPassword
          ]);
  
          //Force change AD Password
          // $adPassword = str_replace("\n", "", shell_exec("echo -n '\"" . $req-&gt;password . "\"' | recode latin1..utf-16le/base64"));
          // $provider = Adldap\Models\User::connect('ad');
          // $dn = $provider-&gt;search()-&gt;where('cn', $req-&gt;userid)-&gt;get();
          // $res = $dn-&gt;setPassword($adPassword);
  
          if ($res) {
              return back()-&gt;withSuccess('&lt;strong&gt;Success!&lt;/strong&gt; Your password has been changed');
          } else {
              return back()-&gt;withErrors('&lt;strong&gt;Failed!&lt;/strong&gt; Your password was unable to changed');
          }
      }
  </code></pre>
  
  <p>Unfortunately $res = $dn->setPassword($adPassword); returns error 'Method Adldap\Query\Collection::setPassword does not exist.'</p>