<commit_before><?php

/**
 * @copyright  <NAME>
 * @license    http://www.makoframework.com/license
 */

namespace mako\security;

/**
 * Secure password hashing and validation.
 *
 * @author  <NAME>
 */

class Password
{
	/**
	 * Default computing costs.
	 *
	 * @var array
	 */

	protected static $costs = 
	[
		PASSWORD_BCRYPT => 10,
	];

	/**
	 * Protected constructor since this is a static class.
	 *
	 * @access  protected
	 */

	protected function __construct()
	{
		// Nothing here
	}

	/**
	 * Normalizes the cost value.
	 * 
	 * @access  protected
	 * @param   int        $cost  Computing cost
	 * @return  int
	 */

	protected static function normalizeCost($cost)
	{
		switch(PASSWORD_DEFAULT)
		{
			case PASSWORD_BCRYPT:
				$cost = ($cost < 4 || $cost > 31) ? static::$costs[PASSWORD_BCRYPT] : $cost;
				break;
		}

		return $cost;
	}

	/**
	 * Set Default computing cost.
	 * 
	 * @access  public
	 * @param   int     $cost  Computing cost
	 */

	public static function setDefaultComputingCost($cost)
	{
		static::$costs[PASSWORD_DEFAULT] = static::normalizeCost($cost);
	}

	/**
	 * Returns a password hash.
	 *
	 * @access  public
	 * @param   string    $password  Password
	 * @param   null|int  $cost      Computing cost
	 * @return  string
	 */

	public static function hash($password, $cost = null)
	{
		$cost = static::normalizeCost($cost ?: static::$costs[PASSWORD_DEFAULT]);

		return password_hash($password, PASSWORD_DEFAULT, ['cost' => $cost]);
	}

	/**
	 * Checks if the password needs to be rehashed.
	 * 
	 * @access  public
	 * @param   string    $hash  Password hash to check
	 * @param   null|int  $cost  Computing cost
	 * @return  string
	 */

	public static function needsRehash($hash, $cost = null)
	{
		$cost = static::normalizeCost($cost ?: static::$costs[PASSWORD_DEFAULT]);

		return password_needs_rehash($hash, PASSWORD_DEFAULT, ['cost' => $cost]);
	}<commit_msg>Fixed return type in docblock<commit_after><?php

/**
 * @copyright  <NAME>
 * @license    http://www.makoframework.com/license
 */

namespace mako\security;

/**
 * Secure password hashing and validation.
 *
 * @author  <NAME>
 */

class Password
{
	/**
	 * Default computing costs.
	 *
	 * @var array
	 */

	protected static $costs = 
	[
		PASSWORD_BCRYPT => 10,
	];

	/**
	 * Protected constructor since this is a static class.
	 *
	 * @access  protected
	 */

	protected function __construct()
	{
		// Nothing here
	}

	/**
	 * Normalizes the cost value.
	 * 
	 * @access  protected
	 * @param   int        $cost  Computing cost
	 * @return  int
	 */

	protected static function normalizeCost($cost)
	{
		switch(PASSWORD_DEFAULT)
		{
			case PASSWORD_BCRYPT:
				$cost = ($cost < 4 || $cost > 31) ? static::$costs[PASSWORD_BCRYPT] : $cost;
				break;
		}

		return $cost;
	}

	/**
	 * Set Default computing cost.
	 * 
	 * @access  public
	 * @param   int     $cost  Computing cost
	 */

	public static function setDefaultComputingCost($cost)
	{
		static::$costs[PASSWORD_DEFAULT] = static::normalizeCost($cost);
	}

	/**
	 * Returns a password hash.
	 *
	 * @access  public
	 * @param   string    $password  Password
	 * @param   null|int  $cost      Computing cost
	 * @return  string
	 */

	public static function hash($password, $cost = null)
	{
		$cost = static::normalizeCost($cost ?: static::$costs[PASSWORD_DEFAULT]);

		return password_hash($password, PASSWORD_DEFAULT, ['cost' => $cost]);
	}

	/**
	 * Checks if the password needs to be rehashed.
	 * 
	 * @access  public
	 * @param   string    $hash  Password hash to check
	 * @param   null|int  $cost  Computing cost
	 * @return  boolean
	 */

	public static function needsRehash($hash, $cost = null)
	{
		$cost = static::normalizeCost($cost ?: static::$costs[PASSWORD_DEFAULT]);

		return password_needs_rehash($hash, PASSWORD_DEFAULT, ['cost' => $cost]);
	}
{'fraction_non_alphanumeric': 0.1346204017740673, 'fraction_numerical': 0.0026089225150013043, 'mean_word_length': 3.02308499475341, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2111348', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1228, 'n_words': 318}