Pop\Crypt\Sha::create PHP Method

create() public method

Method to create the hashed value
public create ( string $string ) : string
$string string
return string
    public function create($string)
    {
        $hash = null;
        $prefix = $this->bits == 512 ? '$6$' : '$5$';
        $prefix .= 'rounds=' . $this->rounds . '$';
        $this->salt = null === $this->salt ? substr(str_replace('+', '.', base64_encode(String::random(32))), 0, 16) : substr(str_replace('+', '.', base64_encode($this->salt)), 0, 16);
        $hash = crypt($string, $prefix . $this->salt);
        return $hash;
    }

Usage Example

示例#1
0
 public function testSha512()
 {
     $crypt = new Crypt\Sha(512);
     $crypt->setRounds(1000000000);
     $this->assertEquals(999999999, $crypt->getRounds());
     $crypt->setRounds(100);
     $this->assertEquals(1000, $crypt->getRounds());
     $this->assertEquals(512, $crypt->getBits());
     $hash = $crypt->create('12password34');
     $this->assertTrue($crypt->verify('12password34', $hash));
 }
All Usage Examples Of Pop\Crypt\Sha::create