Files
nl-mall-api/system/hash.php

44 lines
822 B
PHP
Raw Normal View History

2011-06-08 23:45:08 -05:00
<?php namespace System;
class Hash {
/**
2011-07-11 12:15:06 -07:00
* Hash a string using PHPass.
*
* PHPass provides reliable bcrypt hashing, and is used by many popular PHP
* applications such as Wordpress and Joomla.
2011-06-08 23:45:08 -05:00
*
2011-07-11 12:15:06 -07:00
* @access public
* @param string $value
* @return string
2011-06-08 23:45:08 -05:00
*/
2011-07-11 12:15:06 -07:00
public static function make($value)
{
return static::hasher()->HashPassword($value);
}
2011-06-08 23:45:08 -05:00
/**
2011-07-11 12:15:06 -07:00
* Determine if an unhashed value matches a given hash.
2011-06-08 23:45:08 -05:00
*
* @param string $value
2011-07-11 12:15:06 -07:00
* @param string $hash
* @return bool
2011-06-08 23:45:08 -05:00
*/
2011-07-11 12:15:06 -07:00
public static function check($value, $hash)
2011-06-08 23:45:08 -05:00
{
2011-07-11 12:15:06 -07:00
return static::hasher()->CheckPassword($value, $hash);
2011-06-08 23:45:08 -05:00
}
/**
2011-07-11 12:15:06 -07:00
* Create a new PHPass instance.
2011-06-08 23:45:08 -05:00
*
2011-07-11 12:15:06 -07:00
* @return PasswordHash
2011-06-08 23:45:08 -05:00
*/
2011-07-11 12:15:06 -07:00
private static function hasher()
2011-06-08 23:45:08 -05:00
{
2011-07-11 12:15:06 -07:00
require_once SYS_PATH.'vendor/phpass'.EXT;
return new \PasswordHash(10, false);
2011-06-08 23:45:08 -05:00
}
}