Skip to content

Instantly share code, notes, and snippets.

@diegofelix
Created June 30, 2016 18:55
Show Gist options
  • Save diegofelix/49da3c9269de0e2df1b804692214f5ff to your computer and use it in GitHub Desktop.
Save diegofelix/49da3c9269de0e2df1b804692214f5ff to your computer and use it in GitHub Desktop.
Keygen.php
<?php
namespace App\Services;
class Keygen {
/**
* Removed zeroes and o's to avoid missreading
*
* @var string
*/
protected static $hash = 'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789';
/**
* Generate a hash with strings separated by a -
*
* @param integer $limit
* @param integer $chunkSize
* @return string
*/
public static function make($limit = 11, $chunkSize = 3)
{
return substr(chunk_split(str_shuffle(static::$hash), $chunkSize, '-'), 0, $limit);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment