Skip to content

Instantly share code, notes, and snippets.

@felladrin
Created October 30, 2018 17:26
Show Gist options
  • Select an option

  • Save felladrin/bd3521973837f448f68a9a1b13f9d8c5 to your computer and use it in GitHub Desktop.

Select an option

Save felladrin/bd3521973837f448f68a9a1b13f9d8c5 to your computer and use it in GitHub Desktop.
<?php
class Bcrypt
{
private static $cost = 10;
public static function encode($string)
{
$salt = substr(base_convert(sha1(uniqid(mt_rand(), true)), 16, 36), 0, 22);
$param = sprintf('$2a$%02d$%s$', self::$cost, $salt);
return crypt($string, $param);
}
public static function match($string, $encoded)
{
return $encoded === crypt($string, $encoded);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment