Ver Mensaje Individual
  #2 (permalink)  
Antiguo 25/05/2010, 10:33
Avatar de HiToGoRoShi
HiToGoRoShi
 
Fecha de Ingreso: abril-2008
Mensajes: 849
Antigüedad: 16 años
Puntos: 31
Respuesta: Comparar contraseñas del phpbb3?

gracias por la ayuda ¬¬ .......

Jajaja es broma ya encontre la solucion, y quiisirea que algun genio me explique el porque no funcionaba pero antes voy a explicarle a todos como hacerlo.

Primero creamos nuestro archivo

hash.php
Código PHP:
Ver original
  1. <?php
  2. /**
  3. * Check for correct password
  4. *
  5. * @param string $password The password in plain text
  6. * @param string $hash The stored password hash
  7. *
  8. * @return bool Returns true if the password is correct, false if not.
  9. */
  10. function phpbb_check_hash($password, $hash)
  11. {
  12.     $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  13.     if (strlen($hash) == 34)
  14.     {
  15.         return (_hash_crypt_private($password, $hash, $itoa64) === $hash) ? true : false;
  16.     }
  17.  
  18.     return (md5($password) === $hash) ? true : false;
  19. }
  20.  
  21. /**
  22. * Generate salt for hash generation
  23. */
  24. function _hash_gensalt_private($input, &$itoa64, $iteration_count_log2 = 6)
  25. {
  26.     if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31)
  27.     {
  28.         $iteration_count_log2 = 8;
  29.     }
  30.  
  31.     $output = '$H$';
  32.     $output .= $itoa64[min($iteration_count_log2 + ((PHP_VERSION >= 5) ? 5 : 3), 30)];
  33.     $output .= _hash_encode64($input, 6, $itoa64);
  34.  
  35.     return $output;
  36. }
  37.  
  38. /**
  39. * Encode hash
  40. */
  41. function _hash_encode64($input, $count, &$itoa64)
  42. {
  43.     $output = '';
  44.     $i = 0;
  45.  
  46.     do
  47.     {
  48.         $value = ord($input[$i++]);
  49.         $output .= $itoa64[$value & 0x3f];
  50.  
  51.         if ($i < $count)
  52.         {
  53.             $value |= ord($input[$i]) << 8;
  54.         }
  55.  
  56.         $output .= $itoa64[($value >> 6) & 0x3f];
  57.  
  58.         if ($i++ >= $count)
  59.         {
  60.             break;
  61.         }
  62.  
  63.         if ($i < $count)
  64.         {
  65.             $value |= ord($input[$i]) << 16;
  66.         }
  67.  
  68.         $output .= $itoa64[($value >> 12) & 0x3f];
  69.  
  70.         if ($i++ >= $count)
  71.         {
  72.             break;
  73.         }
  74.  
  75.         $output .= $itoa64[($value >> 18) & 0x3f];
  76.     }
  77.     while ($i < $count);
  78.  
  79.     return $output;
  80. }
  81.  
  82. /**
  83. * The crypt function/replacement
  84. */
  85. function _hash_crypt_private($password, $setting, &$itoa64)
  86. {
  87.     $output = '*';
  88.  
  89.     // Check for correct hash
  90.     if (substr($setting, 0, 3) != '$H$')
  91.     {
  92.         return $output;
  93.     }
  94.  
  95.     $count_log2 = strpos($itoa64, $setting[3]);
  96.  
  97.     if ($count_log2 < 7 || $count_log2 > 30)
  98.     {
  99.         return $output;
  100.     }
  101.  
  102.     $count = 1 << $count_log2;
  103.     $salt = substr($setting, 4, 8);
  104.  
  105.     if (strlen($salt) != 8)
  106.     {
  107.         return $output;
  108.     }
  109.  
  110.     /**
  111.     * We're kind of forced to use MD5 here since it's the only
  112.     * cryptographic primitive available in all versions of PHP
  113.     * currently in use.  To implement our own low-level crypto
  114.     * in PHP would result in much worse performance and
  115.     * consequently in lower iteration counts and hashes that are
  116.     * quicker to crack (by non-PHP code).
  117.     */
  118.     if (PHP_VERSION >= 5)
  119.     {
  120.         $hash = md5($salt . $password, true);
  121.         do
  122.         {
  123.             $hash = md5($hash . $password, true);
  124.         }
  125.         while (--$count);
  126.     }
  127.     else
  128.     {
  129.         $hash = pack('H*', md5($salt . $password));
  130.         do
  131.         {
  132.             $hash = pack('H*', md5($hash . $password));
  133.         }
  134.         while (--$count);
  135.     }
  136.  
  137.     $output = substr($setting, 0, 12);
  138.     $output .= _hash_encode64($hash, 16, $itoa64);
  139.  
  140.     return $output;
  141. }
  142. ?>

Nuestro archivo para comparar los password

validarPassword.php
Código PHP:
Ver original
  1. include_once("hash.php");
  2.  
  3. if (phpbb_check_hash('PASSWORD ORIGINAL', 'PASSWORD HASH'))
  4.     print "GOOD";
  5. else
  6.     print "BAD";

Mi error era que este no acepta comillas, solo apostrofes el cual no tnego idea porque, si alguien me explica seria genial..

Saludos