title: Created Hashed Password in PHP Class
body: <p>So I'm trying to create a Blowfish encrypted password with a salt using a User class that I have created, which in turns extends an overall database object that uses Late Static Bindings to CRUD from my database. Anyway, I'm trying to get this darn thing to encrypt the password before I call the create() method and inset it onto my database but each time when I do put the information in the form it goes to a blank 'update.php' screen (update.php has all my isset($_POST[]) calls for all my forms) and nothing gets uploaded to my database. Here's the code so far...</p>
  
  <h2>Code in update.php</h2>
  
  <pre><code>if (isset($_POST["createAdmin"])) {
  
      $user = new Users();
      $user-&gt;password = $user-&gt;password_encrypt($_POST['new_password']);
      $user-&gt;username = $_POST['new_username'];
      $user-&gt;first_name = $_POST['first_name'];
      $user-&gt;last_name = $_POST['last_name'];
      if($user-&gt;create()) {
          $_SESSION['new_admin_message'] = $user-&gt;password;
          redirect_to("../public/admin/manage_admin.php");
      }
      else {
          $_SESSION['new_admin_message'] ="Admin didn't create successfully";
          redirect_to("../public/admin/manage_admin.php");
      }
  }
  </code></pre>
  
  <h2>Code in user.php (the user class)</h2>
  
  <pre><code>&lt;?php
  require_once(LIB_PATH.DS.'database.php');
  
  class Users extends DatabaseObject {
  
  
      protected static $table_name="users";
      protected static $db_fields = array('id', 'username', 'password', 'first_name', 'last_name');
      public $id;
      public $username;
      public $password;
      public $first_name;
      public $last_name;
  
  public static function password_encrypt($password) {
      $hashed_format = "2y$10$"; // Tels PHP to use Blowfish with a "cost" of 10
      $salt_length = 22; // Blowfish salts should be 22-characters or more
      $salt = generate_salt($salt_length);
      $format_and_salt = $hash_format . $salt; 
      $hash = crypt($password, $format_and_salt);
      return $hash;
  }
  
  private function generate_salt($length) {
      // Not 100% unique, not 100% random, but good enoguh for a salt 
      // MD5 returns 32 characters
      $unique_random_string = md5(uniqid(mt_rand(), true));
  
      // Valid caracters for a solt are [a-zA-Z0-9./]
      $base64_string = base64_encode($unique_random_string);
  
      // But not '+' which is valid in base64 encoding
      $modified_base64_string = str_replace('+', ".", $base64_string);
  
      //Truncate string to the correct length
      $salt = substr($modified_base64_string, 0, $length);
  
      return $salt;
  }
  </code></pre>
  
  <p>There's a couple other methods in the class that aren't important for this particular problem. I'm relatively new to OOP and PHP in general so any help would be greatly appreciated. If you could leave a short description on how you fixed the problem that would be awesome too. Thanks!!</p>