Пример #1
0
 /**
  * Generate a config string from an array.
  *
  * @param array $config Array of configuration options.
  * @return string Configuration string.
  * @throws InvalidArgumentException Throws an InvalidArgumentException if
  *     any passed-in configuration options are invalid.
  */
 public static function genConfig(array $config = array())
 {
     $defaults = array('salt' => Utilities::encode64(Utilities::genRandomBytes(1)));
     $config = array_merge($defaults, array_change_key_case($config, CASE_LOWER));
     $string = '*1';
     if (self::validateOptions($config)) {
         $string = $config['salt'];
     }
     return $string;
 }
Пример #2
0
 /**
  * Generate a config string from an array.
  *
  * @param array $config Array of configuration options.
  * @return string Configuration string.
  * @throws InvalidArgumentException Throws an InvalidArgumentException if
  *     any passed-in configuration options are invalid.
  */
 public static function genConfig(array $config = array())
 {
     $defaults = array('rounds' => 40000, 'salt' => Utilities::encode64(Utilities::genRandomBytes(6)));
     $config = array_merge($defaults, array_change_key_case($config, CASE_LOWER));
     $string = '*1';
     if (self::validateOptions($config)) {
         $string = sprintf('$sha1$%d$%s', $config['rounds'], $config['salt']);
     }
     return $string;
 }
Пример #3
0
 /**
  * Generate a config string from an array.
  *
  * @param array $config Array of configuration options.
  * @return string Configuration string.
  * @throws InvalidArgumentException Throws an InvalidArgumentException if
  *     any passed-in configuration options are invalid.
  */
 public static function genConfig(array $config = array())
 {
     $defaults = array('ident' => self::IDENT_PHPASS, 'rounds' => 16, 'salt' => Utilities::encode64(Utilities::genRandomBytes(6)));
     $config = array_merge($defaults, array_change_key_case($config, CASE_LOWER));
     $string = '*1';
     if (self::validateOptions($config)) {
         $charset = Utilities::CHARS_H64;
         $string = sprintf('$%s$%s%s', $config['ident'], $charset[(int) $config['rounds']], $config['salt']);
     }
     return $string;
 }
Пример #4
0
 /**
  * Generate a config string from an array.
  *
  * @param array $config Array of configuration options.
  * @return string Configuration string.
  * @throws InvalidArgumentException Throws an InvalidArgumentException if
  *     any passed-in configuration options are invalid.
  */
 public static function genConfig(array $config = array())
 {
     $defaults = array('rounds' => 5001, 'salt' => Utilities::encode64(Utilities::genRandomBytes(3)));
     $config = array_merge($defaults, array_change_key_case($config, CASE_LOWER));
     $string = '*1';
     if (self::validateOptions($config)) {
         // Rounds needs to be odd in order to avoid exposing weak DES keys
         if ($config['rounds'] % 2 == 0) {
             --$config['rounds'];
         }
         $string = sprintf('_%s%s', Utilities::encodeInt24($config['rounds']), $config['salt']);
     }
     return $string;
 }
Пример #5
0
 /**
  * @param string $input
  * @return string
  */
 protected static function genSalt($input = null)
 {
     if (!$input) {
         $input = Utilities::genRandomBytes(16);
     }
     $count = strlen($input);
     $atoi64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
     $output = '';
     $i = 0;
     do {
         $c1 = ord($input[$i++]);
         $output .= $atoi64[$c1 >> 2];
         $c1 = ($c1 & 0x3) << 4;
         if ($i >= $count) {
             $output .= $atoi64[$c1];
             break;
         }
         $c2 = ord($input[$i++]);
         $c1 |= $c2 >> 4;
         $output .= $atoi64[$c1];
         $c1 = ($c2 & 0xf) << 2;
         $c2 = ord($input[$i++]);
         $c1 |= $c2 >> 6;
         $output .= $atoi64[$c1];
         $output .= $atoi64[$c2 & 0x3f];
     } while (1);
     return $output;
 }
Пример #6
0
 /**
  * @param string $input
  * @return string
  */
 protected static function genSalt($input = null)
 {
     if (!$input) {
         $input = Utilities::genRandomBytes(16);
     }
     return Utilities::altBase64Encode($input);
 }