title: How do I encrypt a password in Wordpress using Wordpress salt?
body: <p>I want to encrypt the password being sent into the database, with the standard Wordpress salt, just like Wordpress does it when you create a new user. I know I can find my salt in the wp-config.php. So I don't need to generate the salt; I just need to encrypt the password.</p>
  
  <p>So that when I create mypassword0, what is sent to the database is the string of text encrypted by my Wordpress salt.</p>
  
  <p>Here is my original code that works. (thank you <a href="https://stackoverflow.com/users/2257413/yadav-chetan">Yadav Chetan</a> for your help!) Now I just need to add the salt encryption code.</p>
  
  <pre><code>  &lt;?php
          if(isset($_POST['submit'])){
  
          $query = "INSERT INTO mytable_one
            (user, pass)
            VALUES
            ('".$_POST['user']."', '".$_POST['pass']."')";
  
          $query = "INSERT INTO mytable_two
            (fname, lname)
            VALUES
            ('".$_POST['fname']."', '".$_POST['lname']."')";
  
          mysql_query($query);
  
           }else{
      ?&gt;
      &lt;div class="content"&gt;
          &lt;form method="post"&gt;
              &lt;div&gt;&lt;strong&gt;First Name:&lt;/strong&gt;&lt;span class="errortext"&gt;*&lt;/span&gt;&lt;/div&gt;
              &lt;div&gt;&lt;input id="first-name" name="fname" type="text" /&gt;&lt;/div&gt;
  
              &lt;div&gt;&lt;strong&gt;Last Name:&lt;/strong&gt;&lt;span class="errortext"&gt;*&lt;/span&gt;&lt;/div&gt;
              &lt;div&gt;&lt;input id="last-name" name="lname" type="text" /&gt;&lt;/div&gt;
  
              &lt;div&gt;&lt;strong&gt;User:&lt;/strong&gt;&lt;span class="errortext"&gt;*&lt;/span&gt;&lt;/div&gt;
              &lt;div&gt;&lt;input id="user-login" name="user" type="text" /&gt;&lt;/div&gt;
  
              &lt;div&gt;&lt;strong&gt;Password:&lt;/strong&gt;&lt;span class="errortext"&gt;*&lt;/span&gt;&lt;/div&gt;
              &lt;div&gt;&lt;input id="user-pass" name="pass" type="text" /&gt;&lt;/div&gt;
  
              &lt;div&gt;&lt;input id="submit-button" value="submit" type="submit" /&gt;
          &lt;/div&gt;          
          &lt;/form&gt;
      &lt;?php }?&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>UPDATED:</strong></p>
  
  <p><a href="https://stackoverflow.com/users/1370034/rrikesh">RRikesh</a> suggested I change the mysql_* to WPDB code. So I tried to change it over to wpdb, and also I need to integrate it in with the other code. So can you help me fix this updated code?</p>
  
  <pre><code>&lt;?php
      if(isset($_POST['submit'])){
  
  
      $firstname = $_POST['fname'];
      $lastname = $_POST['lname'];
      $username = $_POST['user'];
      $password = $_POST['pass'];
  
      $wpdb-&gt;query( 
          $wpdb-&gt;prepare( 
             "INSERT INTO  mytable_one
            (user, pass) VALUES (%s, %s)",
               $username,
               wp_hash_password($password)
        )
      );
      $wpdb-&gt;query( 
          $wpdb-&gt;prepare( 
              "INSERT INTO  mytable_two
              (fname, lname) VALUES (%s, %s)",
                 $firstname,
                 $lastname,
          )
      );
  
      }else{
  ?&gt;
  &lt;div class="content"&gt;
      &lt;form method="post"&gt;
                  &lt;div&gt;&lt;strong&gt;First Name:&lt;/strong&gt;&lt;span class="errortext"&gt;*&lt;/span&gt;&lt;/div&gt;
                  &lt;div&gt;&lt;input id="first-name" name="fname" type="text" /&gt;&lt;/div&gt;
  
                  &lt;div&gt;&lt;strong&gt;Last Name:&lt;/strong&gt;&lt;span class="errortext"&gt;*&lt;/span&gt;&lt;/div&gt;
                  &lt;div&gt;&lt;input id="last-name" name="lname" type="text" /&gt;&lt;/div&gt;
  
                  &lt;div&gt;&lt;strong&gt;Username:&lt;/strong&gt;&lt;span class="errortext"&gt;*&lt;/span&gt;&lt;/div&gt;
                  &lt;div&gt;&lt;input id="user-login" name="user" type="text" /&gt;&lt;/div&gt;
  
                  &lt;div&gt;Password:&lt;/div&gt;
                  &lt;div&gt;&lt;input id="user-pass" name="pass" type="text" /&gt;&lt;/div&gt;
  
          &lt;div&gt;&lt;input id="submit-button" value="submit" name="submit" type="submit" /&gt;&lt;/div&gt;          
      &lt;/form&gt;
  &lt;?php }?&gt;
  </code></pre>
  
  <hr>
  
  <hr>
  
  <p><strong>UPDATE2</strong></p>
  
  <p>I was unable to get the WPDB method to work. however, using my otd method I was able to has the password. Here is the working code:</p>
  
  <pre><code>    &lt;?php
          if(isset($_POST['submit'])){
  
              $password = $_POST['user_pass'];
              $hash = wp_hash_password('$password');
  
              $query = "INSERT INTO wp_users
                (fname, lname, user, pass) VALUES ('".$_POST['fname']."', '".$_POST['lname']."', '".$_POST['user']."', '".$hash."')";
  
              mysql_query($query);
  
          }else{
      ?&gt;
  </code></pre>
  
  <p>Perhaps I should open a new question about the WPDB because this question was about hashing the password, which is solved.</p>