. * */ namespace Vvveb\System\User; class Auth { static $options = ['cost' => 11]; public static function sanitize(&$data) { if (isset($data['username'])) { $data['username'] = preg_replace('/[^\w-]/', '', $data['username']); } if (isset($data['email'])) { $data['email'] = filter_var($data['email'], FILTER_VALIDATE_EMAIL); } } public static function checkPassword($password, $hash) { if (password_verify($password, $hash)) { // Check if a newer hashing algorithm is available // or the cost has changed if (password_needs_rehash($hash, PASSWORD_DEFAULT, self :: $options)) { // If so, create a new hash, and replace the old one return $newHash = password_hash($password, PASSWORD_DEFAULT, self :: $options); } return true; } return false; } public static function password($password) { return password_hash($password, PASSWORD_DEFAULT, self :: $options); } }