Segunda-feira, 21 de maio de 2012
Seu IP de acesso:
38.107.179.234
Principal
Portfólio
Publicações
Links
Downloads
Contato
Enter your search terms
Submit search form
PUBLICAÇÕES
PHP /
LDAP - Criar HASH da senha em MD5, SHA e SSHA.
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- // Função: password_hash // Propósito: Gerar hash da senha conforme o tipo de criptografia. // Utilização: password_hash($password_clear, $enc_type) // - $password_clear: A senha em texto plano à ser codificada. // - $enc_type: Tipo de hash para criptografar. // - md5, sha, ssha ou clear. // Retorno: String do hash gerado. // ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- function password_hash($password_clear, $enc_type){ $enc_type = strtolower( $enc_type ); switch( $enc_type ) { case 'md5': $new_value = '{MD5}' . base64_encode( pack( 'H*' , md5( $password_clear) ) ); break; case 'sha': if( function_exists('sha1') ) { // use php 4.3.0+ sha1 function, if it is available. $new_value = '{SHA}' . base64_encode( pack( 'H*' , sha1( $password_clear) ) ); } elseif( function_exists( 'mhash' ) ) { $new_value = '{SHA}' . base64_encode( mhash( MHASH_SHA1, $password_clear) ); } else { print('Your PHP install does not have the mhash() function. Cannot do SHA hashes.'); } break; case 'ssha': if( function_exists( 'mhash' ) && function_exists( 'mhash_keygen_s2k' ) ) { mt_srand( (double) microtime() * 1000000 ); $salt = mhash_keygen_s2k( MHASH_SHA1, $password_clear, substr( pack( "h*", md5( mt_rand() ) ), 0, 8 ), 4 ); $new_value = "{SSHA}".base64_encode( mhash( MHASH_SHA1, $password_clear.$salt ).$salt ); } else { print('Your PHP install does not have the mhash() function. Cannot do SHA hashes.'); } break; case 'clear': default: $new_value = $password_clear; } return $new_value; }
Publicado em: 01/08/08 09:41
[voltar]
© 2004-2012 - Pierin.com
AdSense
—
Analytics
—
Intranet
—
Webmail