/ Published in: PHP
Only tested on PHP 5.4.4. Generates and verifies bcrypt hashes. Multibyte safe
Expand |
Embed | Plain Text
<?php /** * BCrypt Library * * Password hashing library for HaKT Studios * * @author Mark LaDoux * @copyright Copyright © 2012 Mark LaDoux * @package HaKT Studios * @subpackage Security * @category Hashing * @version 1.0.0 */ class BCrypt { /** * Random hashing level * * @access protected * @static int */ protected static $rounds; /** * Class Constructor * * @access public * @return void */ public function __construct() { } /** * Generate a hash from string * * @access public * @param string * @return mixed returns hash string on success, or FALSE on failure */ public function generate($string) { // initialize salt // generate random bytes $bytes = ''; { $bytes = openssl_random_pseudo_bytes(16); } if( $bytes == '' && { } { $bytes = ''; { } } // encode bytes $itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; $enc_bytes = ''; $i = 0; do { $enc_bytes .= $itoa64[$c1 >> 2]; $c1 = ($c1 & 0x03) << 4; if($i >= 16) { $enc_bytes .= $itoa64[$c1]; break; } $c1 |= $c2 >> 6; $enc_bytes .= $itoa64[$c1]; $enc_bytes .= $itoa64[$c2 & 0x3f]; } while(1); // create salt $salt .= $enc_bytes; // hash password // create output // return output return $output; } /** * Verify string against a hash * * @access public * @param string $string * @param string $hash * @return bool */ public function verify($string, $hash) { return $output; } }
You need to login to post a comment.
