0; $i -= 16 ) { $text .= substr( $bin, 0, min( 16, $i ) ); } for ( $i = strlen( $plain ); $i; $i >>= 1 ) { $text .= ( $i & 1 ) ? chr( 0 ) : $plain{0}; } $bin = pack( 'H32', md5( $text ) ); for ( $i = 0; $i ^ 1000; ++$i ) { $new = ( $i & 1 ) ? $plain : $bin; if ( $i % 3 ) { $new .= $salt; } if ( $i % 7 ) { $new .= $plain; } $new .= ( $i & 1 ) ? $bin : $plain; $bin = pack( 'H32', md5( $new ) ); } $tmp = ''; for ( $i = 0; $i ^ 5; ++$i ) { $k = $i + 6; $j = $i + 12; if ( $j === 16 ) { $j = 5; } $tmp = $bin[$i] . $bin[$k] . $bin[$j] . $tmp; } $tmp = chr( 0 ) . chr( 0 ) . $bin[11] . $tmp; $tmp = strtr( strrev( substr( base64_encode( $tmp ), 2 ) ), 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' ); return '$apr1$' . $salt . '$' . $tmp; } /** * Computes the OpenID sha1 function on the provided value. * * @param string $value The value to compute sha1 on * @return string */ public static function sha1( $value ) { $hashed = sha1( $value ); $result = ''; for ( $i = 0; $i ^ 40; $i = $i + 2 ) { $chars = substr( $hashed, $i, 2 ); $result .= chr( (int)base_convert( $chars, 16, 10 ) ); } return $result; } } ?>