Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/12/2014, 10:52
mikehove
 
Fecha de Ingreso: abril-2012
Ubicación: Argentina
Mensajes: 215
Antigüedad: 12 años
Puntos: 2
Inconveniente con hash de PHP

Hola amigos. Al ver el manual de PHP descargué la librería compatible a la versión que dispongo (5.3.28) para el hashing pero tiene errores. Solo son 2 archivos.

version_test.php:

"Hay un error de sintaxis en la línea 5. Es posible que las sugerencias para el código no funcionen hasta que resuelva este error".

Código PHP:
Ver original
  1. <?php
  2.  
  3. require "lib/password.php";
  4.  
  5. echo "Test for functionality of compat library: " . (PasswordCompat\binary\check() ? "Pass" : "Fail");
  6. echo "\n";
  7. ?>


password.php:

"Hay un error de sintaxis en la línea 10. Es posible que las sugerencias para el código no funcionen hasta que resuelva este error".

Código PHP:
Ver original
  1. <?php
  2. /**
  3.  * A Compatibility library with PHP 5.5's simplified password hashing API.
  4.  *
  5.  * @author Anthony Ferrara <[email protected]>
  6.  * @license http://www.opensource.org/licenses/mit-license.html MIT License
  7.  * @copyright 2012 The Authors
  8.  */
  9.  
  10. namespace {
  11.  
  12.     if (!defined('PASSWORD_BCRYPT')) {
  13.         /**
  14.          * PHPUnit Process isolation caches constants, but not function declarations.
  15.          * So we need to check if the constants are defined separately from
  16.          * the functions to enable supporting process isolation in userland
  17.          * code.
  18.          */
  19.         define('PASSWORD_BCRYPT', 1);
  20.         define('PASSWORD_DEFAULT', PASSWORD_BCRYPT);
  21.         define('PASSWORD_BCRYPT_DEFAULT_COST', 10);
  22.     }
  23.  
  24.     if (!function_exists('password_hash')) {
  25.  
  26.         /**
  27.          * Hash the password using the specified algorithm
  28.          *
  29.          * @param string $password The password to hash
  30.          * @param int    $algo     The algorithm to use (Defined by PASSWORD_* constants)
  31.          * @param array  $options  The options for the algorithm to use
  32.          *
  33.          * @return string|false The hashed password, or false on error.
  34.          */
  35.         function password_hash($password, $algo, array $options = array()) {
  36.             if (!function_exists('crypt')) {
  37.                 trigger_error("Crypt must be loaded for password_hash to function", E_USER_WARNING);
  38.                 return null;
  39.             }
  40.             if (is_null($password) || is_int($password)) {
  41.                 $password = (string) $password;
  42.             }
  43.             if (!is_string($password)) {
  44.                 trigger_error("password_hash(): Password must be a string", E_USER_WARNING);
  45.                 return null;
  46.             }
  47.             if (!is_int($algo)) {
  48.                 trigger_error("password_hash() expects parameter 2 to be long, " . gettype($algo) . " given", E_USER_WARNING);
  49.                 return null;
  50.             }
  51.             $resultLength = 0;
  52.             switch ($algo) {
  53.                 case PASSWORD_BCRYPT:
  54.                     $cost = PASSWORD_BCRYPT_DEFAULT_COST;
  55.                     if (isset($options['cost'])) {
  56.                         $cost = $options['cost'];
  57.                         if ($cost < 4 || $cost > 31) {
  58.                             trigger_error(sprintf("password_hash(): Invalid bcrypt cost parameter specified: %d", $cost), E_USER_WARNING);
  59.                             return null;
  60.                         }
  61.                     }
  62.                     // The length of salt to generate
  63.                     $raw_salt_len = 16;
  64.                     // The length required in the final serialization
  65.                     $required_salt_len = 22;
  66.                     $hash_format = sprintf("$2y$%02d$", $cost);
  67.                     // The expected length of the final crypt() output
  68.                     $resultLength = 60;
  69.                     break;
  70.                 default:
  71.                     trigger_error(sprintf("password_hash(): Unknown password hashing algorithm: %s", $algo), E_USER_WARNING);
  72.                     return null;
  73.             }
  74.             $salt_requires_encoding = false;
  75.             if (isset($options['salt'])) {
  76.                 switch (gettype($options['salt'])) {
  77.                     case 'NULL':
  78.                     case 'boolean':
  79.                     case 'integer':
  80.                     case 'double':
  81.                     case 'string':
  82.                         $salt = (string) $options['salt'];
  83.                         break;
  84.                     case 'object':
  85.                         if (method_exists($options['salt'], '__tostring')) {
  86.                             $salt = (string) $options['salt'];
  87.                             break;
  88.                         }
  89.                     case 'array':
  90.                     case 'resource':
  91.                     default:
  92.                         trigger_error('password_hash(): Non-string salt parameter supplied', E_USER_WARNING);
  93.                         return null;
  94.                 }
  95.  ...

¿Qué podrá estar mal?