title: Change Filezilla user passwords with PHP SHA512 and Salt
body: <p>We're trying to match our Filezilla Server 0.9.6 user passwords to those that the user chooses for logging into our site with.  All googling points to old solutions that implement MD5, but the newer versions use SHA512 and Salt.  The below code successfully updates the Server XML file, but the new passwords are not working after restarting Filezilla.</p>
  
  <p>Does anyone have experience in this, and can point out where this code is incorrect?</p>
  
  <p><strong>My Code</strong>
  From <a href="https://forum.filezilla-project.org/viewtopic.php?t=39934" rel="nofollow noreferrer">https://forum.filezilla-project.org/viewtopic.php?t=39934</a></p>
  
  <pre><code>&lt;?php
  $password = "myNewPassword";
  
  $seed = str_split("!\"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~");
  shuffle($seed);
  $rand = '';
  foreach (array_rand($seed, 64) as $k) {
      $rand .= $seed[$k];
  }
  $salt_raw = utf8_encode($rand);
  $salt_html = htmlentities($salt_raw);
  $password = utf8_encode($password);
  $salted_password = $password . $salt_raw;
  $encoded_password = strtoupper(hash('SHA512', $salted_password));
  
  // For Filezilla
  $FzPass = $encoded_password;
  $FzSalt = $salt_html;
  
  $xmlFile = 'C:\path-to\FileZilla Server.xml';
  $xml = simplexml_load_file($xmlFile);
  $Pass = $xml-&gt;xpath("//User[@Name='TheUserName']//Option[@Name='Pass']");
  $Salt = $xml-&gt;xpath("//User[@Name='TheUserName']//Option[@Name='Salt']");
  
  $Pass[0][0] = $FzPass;
  $Salt[0][0] = $FzSalt;
  
  $xml-&gt;formatOutput = true;
  $saved = $xml-&gt;asXML($xmlFile);
  chdir( 'C:\FileZilla Server' );
  exec( '"C:\FileZilla Server\FileZilla Server.exe" /reload-config' );
  </code></pre>
  
  <p><strong>Before the PHP execution  <code>Filezilla Server.xml</code></strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" ?&gt;
  &lt;FileZillaServer&gt;
      &lt;Users&gt;
          &lt;User Name="TheUserName"&gt;
              &lt;Option Name="Pass"&gt;1ED89AFBA4FD8EF177EAAF21E6641C33FC870860D5F399CD9B0A79632B0F2B08B235DB7258DB2B6EB58402AF29A4C8491CC8F82ED9D2E74EABA8F7B240D0615F&lt;/Option&gt;
              &lt;Option Name="Salt"&gt;-Z5c@tci:e?E4E@H@(cq)/W1zDMs#F&amp;gt;XsYd$M)0t#{/s,tc@]GJYf@{@T.&amp;amp;O*5sF&lt;/Option&gt;
              &lt;Option Name="Group"&gt;&lt;/Option&gt;
              &lt;Option Name="Bypass server userlimit"&gt;1&lt;/Option&gt;
              &lt;Option Name="User Limit"&gt;0&lt;/Option&gt;
              &lt;Option Name="IP Limit"&gt;0&lt;/Option&gt;
              &lt;Option Name="Enabled"&gt;1&lt;/Option&gt;
              &lt;Option Name="ForceSsl"&gt;0&lt;/Option&gt;
          &lt;/User&gt;
      &lt;/Users&gt;
  &lt;/FileZillaServer&gt;
  </code></pre>
  
  <p><strong>After the PHP execution</strong></p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;FileZillaServer&gt;
          &lt;User Name="producer"&gt;
              &lt;Option Name="Pass"&gt;57AECC6BBCCC8EE5A73F0E362E2434DBF617EC2C85404205D881B1B7A2D303405789F8B42DFE61EDD7CF197700B66307E998054615C8A9A1CA5A9988029F0EAD&lt;/Option&gt;
              &lt;Option Name="Salt"&gt;P,]mk&amp;amp;amp;4N;v3`#&amp;amp;lt;e8S?oj[U=Ja$}Q6~:\Z1{HuB&amp;amp;gt;bnI/&amp;amp;quot;M-pDh.qFylKfd0|LgT*G&lt;/Option&gt;
              &lt;Option Name="Group"/&gt;
              &lt;Option Name="Bypass server userlimit"&gt;1&lt;/Option&gt;
              &lt;Option Name="User Limit"&gt;0&lt;/Option&gt;
              &lt;Option Name="IP Limit"&gt;0&lt;/Option&gt;
              &lt;Option Name="Enabled"&gt;1&lt;/Option&gt;
              &lt;Option Name="ForceSsl"&gt;0&lt;/Option&gt;
          &lt;/User&gt;
  &lt;/FileZillaServer&gt;
  </code></pre>