Ver Mensaje Individual
  #3 (permalink)  
Antiguo 18/02/2008, 20:08
[DARK_RULO]
 
Fecha de Ingreso: marzo-2005
Mensajes: 70
Antigüedad: 19 años, 1 mes
Puntos: 0
Re: Encriptación de contraseña en phpBB 3.0?

Bueno, no entendí muy bien el problema que tienes (o qué hacías antes a la hora que el usuario ingresaba sus datos en el form) dado que tienes integrado tu sitio con tu phpBB. Muchos también tenemos intregrado nuestras págs con el foro para restringir secciones y todo eso únicamente utilizando la sesión del foro. Aún con el cambio de phpBB 2.0.X a 3.0.X, creo que nadie ha tenido problemas con esto de las contraseñas, ¿o sí? (y vaya que soy un novatazo con esto del PHP u____u)

Pero bue, en efecto, el equipo de phpBB se creo su propio hash para las contraseñas. Husmeando un poco encontré esto en la estructura...

functions.php línea 236
Código PHP:
/**
*
* @version Version 0.1 / $Id: functions.php,v 1.647 2007/12/10 18:35:28 kellanved Exp $
*
* Portable PHP password hashing framework.
*
* Written by Solar Designer <solar at openwall.com> in 2004-2006 and placed in
* the public domain.
*
* There's absolutely no warranty.
*
* The homepage URL for this framework is:
*
*    http://www.openwall.com/phpass/
*
* Please be sure to update the Version line if you edit this file in any way.
* It is suggested that you leave the main version number intact, but indicate
* your project name (after the slash) and add your own revision information.
*
* Please do not change the "private" password hashing method implemented in
* here, thereby making your hashes incompatible.  However, if you must, please
* change the hash type identifier (the "$P$") to something different.
*
* Obviously, since this code is in the public domain, the above are not
* requirements (there can be none), but merely suggestions.
*
*
* Hash the password
*/
function phpbb_hash($password)
{
    
$itoa64 './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';

    
$random_state unique_id();
    
$random '';
    
$count 6;

    if ((
$fh = @fopen('/dev/urandom''rb')))
    {
        
$random fread($fh$count);
        
fclose($fh);
    }

    if (
strlen($random) < $count)
    {
        
$random '';

        for (
$i 0$i $count$i += 16)
        {
            
$random_state md5(unique_id() . $random_state);
            
$random .= pack('H*'md5($random_state));
        }
        
$random substr($random0$count);
    }
    
    
$hash _hash_crypt_private($password_hash_gensalt_private($random$itoa64), $itoa64);

    if (
strlen($hash) == 34)
    {
        return 
$hash;
    }

    return 
md5($password);
}

/**
* Check for correct password
*/
function phpbb_check_hash($password$hash)
{
    
$itoa64 './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    if (
strlen($hash) == 34)
    {
        return (
_hash_crypt_private($password$hash$itoa64) === $hash) ? true false;
    }

    return (
md5($password) === $hash) ? true false;
}

/**
* Generate salt for hash generation
*/
function _hash_gensalt_private($input, &$itoa64$iteration_count_log2 6)
{
    if (
$iteration_count_log2 || $iteration_count_log2 31)
    {
        
$iteration_count_log2 8;
    }

    
$output '$H$';
    
$output .= $itoa64[min($iteration_count_log2 + ((PHP_VERSION >= 5) ? 3), 30)];
    
$output .= _hash_encode64($input6$itoa64);

    return 
$output;
}

/**
* Encode hash
*/
function _hash_encode64($input$count, &$itoa64)
{
    
$output '';
    
$i 0;

    do
    {
        
$value ord($input[$i++]);
        
$output .= $itoa64[$value 0x3f];

        if (
$i $count)
        {
            
$value |= ord($input[$i]) << 8;
        }

        
$output .= $itoa64[($value >> 6) & 0x3f];

        if (
$i++ >= $count)
        {
            break;
        }

        if (
$i $count)
        {
            
$value |= ord($input[$i]) << 16;
        }

        
$output .= $itoa64[($value >> 12) & 0x3f];
        
        if (
$i++ >= $count)
        {
            break;
        }

        
$output .= $itoa64[($value >> 18) & 0x3f];
    }
    while (
$i $count);

    return 
$output;
}

/**
* The crypt function/replacement
*/
function _hash_crypt_private($password$setting, &$itoa64)
{
    
$output '*';

    
// Check for correct hash
    
if (substr($setting03) != '$H$')
    {
        return 
$output;
    }

    
$count_log2 strpos($itoa64$setting[3]);

    if (
$count_log2 || $count_log2 30)
    {
        return 
$output;
    }

    
$count << $count_log2;
    
$salt substr($setting48);

    if (
strlen($salt) != 8)
    {
        return 
$output;
    }

    
/**
    * We're kind of forced to use MD5 here since it's the only
    * cryptographic primitive available in all versions of PHP
    * currently in use.  To implement our own low-level crypto
    * in PHP would result in much worse performance and
    * consequently in lower iteration counts and hashes that are
    * quicker to crack (by non-PHP code).
    */
    
if (PHP_VERSION >= 5)
    {
        
$hash md5($salt $passwordtrue);
        do
        {
            
$hash md5($hash $passwordtrue);
        }
        while (--
$count);
    }
    else
    {
        
$hash pack('H*'md5($salt $password));
        do
        {
            
$hash pack('H*'md5($hash $password));
        }
        while (--
$count);
    }

    
$output substr($setting012);
    
$output .= _hash_encode64($hash16$itoa64);

    return 
$output;

Espero te sirva.

Saludos.