public function create($str) {

    $rand = $this->psl['crypt/rand'];
    $crypto = $this->psl['crypt/crypto'];

    switch($this->method) {
      case self::BCRYPT:
        $saltRnd = $rand->str(22, $this->charsets['itoa64']);
        $salt = sprintf('%s%s$%s', self::BCRYPT, $this->bcrypt_cost, $saltRnd);
        $hash = crypt($str, $salt);
      break;

      case self::PBKDF2:
        $salt = $rand->bytes(64);
        $hash = $crypto->pbkdf2($str, $salt, $this->pbkdf2_c, $this->pbkdf2_dkLen, $this->pbkdf2_prf);

        $hash = sprintf('$pbkdf2$c=%s&dk=%s&f=%s$%s$%s',
                       $this->pbkdf2_c,
                       $this->pbkdf2_dkLen,
                       $this->pbkdf2_prf,
                       base64_encode($hash),
                       base64_encode($salt)
                       );
      break;

      case self::DRUPAL;
        $setting  = '$S$';
        $setting .= $this->charsets['itoa64'][$this->drupal_count];
        $setting .= $this->b64Encode($rand->bytes(6), 6);

        return substr($this->phpassHash($str, $setting), 0, $this->drupal_hashLen);
      break;

      case self::SHA256:
      case self::SHA512:
        $saltRnd = $rand->str(16, $this->charsets['itoa64']);
        $salt = sprintf('%srounds=%s$%s', $this->method, $this->sha2_c, $saltRnd);
        $hash = crypt($str, $salt);
      break;
    }

    if(strlen($hash) > 13) {
      return $hash;
    }
    return false;
  }
public function create($str) {

    $rand = $this->psl['crypt/rand'];
    $crypto = $this->psl['crypt/crypto'];

    switch($this->method) {
      case self::BCRYPT:
        $saltRnd = $rand->str(22, $this->charsets['itoa64']);
        $salt = sprintf('%s%s$%s', self::BCRYPT, $this->bcrypt_cost, $saltRnd);
        $hash = crypt($str, $salt);
      break;

      case self::PBKDF2:
        $salt = $rand->bytes(64);
        $hash = $crypto->pbkdf2($str, $salt, $this->pbkdf2_c, $this->pbkdf2_dkLen, $this->pbkdf2_prf);

        $hash = sprintf('$pbkdf2$c=%s&dk=%s&f=%s$%s$%s',
                       $this->pbkdf2_c,
                       $this->pbkdf2_dkLen,
                       $this->pbkdf2_prf,
                       base64_encode($hash),
                       base64_encode($salt)
                       );
      break;

      case self::DRUPAL;
        $setting  = '$S$';
        $setting .= $this->charsets['itoa64'][$this->drupal_count];
        $setting .= $this->b64Encode($rand->bytes(6), 6);

        return substr($this->phpassHash($str, $setting), 0, $this->drupal_hashLen);
      break;

      case self::SHA256:
      case self::SHA512:
        $saltRnd = $rand->str(16, $this->charsets['itoa64']);
        $salt = sprintf('%srounds=%s$%s', $this->method, $this->sha2_c, $saltRnd);
        $hash = crypt($str, $salt);
      break;
    }

    if(strlen($hash) > 13) {
      return $hash;
    }
    return false;
  }
public function create ( $ str ) { $ rand = $ this -> psl [ 'crypt/rand' ] ; $ crypto = $ this -> psl [ 'crypt/crypto' ] ; switch ( $ this -> method ) { case self :: BCRYPT : $ saltRnd = $ rand -> str ( 22 , $ this -> charsets [ 'itoa64' ] ) ; $ salt = sprintf ( '%s%s$%s' , self :: BCRYPT , $ this -> bcrypt_cost , $ saltRnd ) ; $ hash = crypt ( $ str , $ salt ) ; break ; case self :: PBKDF2 : $ salt = $ rand -> bytes ( 64 ) ; $ hash = $ crypto -> pbkdf2 ( $ str , $ salt , $ this -> pbkdf2_c , $ this -> pbkdf2_dkLen , $ this -> pbkdf2_prf ) ; $ hash = sprintf ( '$pbkdf2$c=%s&dk=%s&f=%s$%s$%s' , $ this -> pbkdf2_c , $ this -> pbkdf2_dkLen , $ this -> pbkdf2_prf , base64_encode ( $ hash ) , base64_encode ( $ salt ) ) ; break ; case self :: DRUPAL ; $ setting = '$S$' ; $ setting .= $ this -> charsets [ 'itoa64' ] [ $ this -> drupal_count ] ; $ setting .= $ this -> b64Encode ( $ rand -> bytes ( 6 ) , 6 ) ; return substr ( $ this -> phpassHash ( $ str , $ setting ) , 0 , $ this -> drupal_hashLen ) ; break ; case self :: SHA256 : case self :: SHA512 : $ saltRnd = $ rand -> str ( 16 , $ this -> charsets [ 'itoa64' ] ) ; $ salt = sprintf ( '%srounds=%s$%s' , $ this -> method , $ this -> sha2_c , $ saltRnd ) ; $ hash = crypt ( $ str , $ salt ) ; break ; } if ( strlen ( $ hash ) > 13 ) { return $ hash ; } return false ; }
Creates a salted hash from a string.

@param string $str
String to hash.

@return string
Returns hashed string, or false on error.
Creates a salted hash from a string .