Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
namespace re-org, bug if missing cookie
- Loading branch information
Showing
11 changed files
with
144 additions
and
127 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
src/Shibalike/Attr/Store/Array.php → src/Shibalike/Attr/Store/ArrayStore.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Shibalike\Util; | ||
|
||
class IdGenerator { | ||
|
||
/** | ||
* Create a random alphanumeric string | ||
* | ||
* @param int $length | ||
* @return string | ||
*/ | ||
public static function generateBase32Id($length = 40) | ||
{ | ||
// generate random bytes, more than we need (adapted from phpass) | ||
$numBytes = $length; | ||
$randomState = microtime(); | ||
if (function_exists('getmypid')) { | ||
$randomState .= getmypid(); | ||
} | ||
$bytes = ''; | ||
if (@is_readable('/dev/urandom') && ($fh = @fopen('/dev/urandom', 'rb'))) { | ||
$bytes = fread($fh, $numBytes); | ||
fclose($fh); | ||
} | ||
if (strlen($bytes) < $numBytes) { | ||
$bytes = ''; | ||
for ($i = 0; $i < $numBytes; $i += 16) { | ||
$randomState = md5(microtime() . $randomState . mt_rand(0, mt_getrandmax())); | ||
$bytes .= pack('H*', md5($randomState)); | ||
} | ||
$bytes = substr($bytes, 0, $numBytes); | ||
} | ||
// convert bytes to base36, strip non-alphanumerics), return a random chunk | ||
return substr(self::_bin_to_base32($bytes), 0, $length); | ||
} | ||
|
||
/** | ||
* Convert binary input to base32 (lossy for speed purposes, not a reversible operation). | ||
* | ||
* @link http://inquisitivecocoa.com/2009/08/10/a-basic-base32_encode-function-for-php/ | ||
* @param string $bytes | ||
* @return string | ||
* @license unknown | ||
*/ | ||
static protected function _bin_to_base32($bytes) { | ||
$hex = unpack('H*', $bytes); | ||
$hex = $hex[1]; | ||
$binary = ''; | ||
for ($i = 0, $l = strlen($hex); $i < $l; $i++) { | ||
$binary .= decbin(hexdec($hex[$i])); | ||
} | ||
|
||
$binaryLength = strlen($binary); | ||
$base32_characters = "0123456789abcdefghijklmnopqrstuv"; | ||
$currentPosition = 0; | ||
$output = ''; | ||
|
||
while ($currentPosition < $binaryLength) { | ||
$bits = substr($binary, $currentPosition, 5); | ||
// don't worry about padding last 5-bit number | ||
|
||
// Convert the 5 bits into a decimal number | ||
// and append the matching character to $output | ||
$output .= $base32_characters[bindec($bits)]; | ||
$currentPosition += 5; | ||
} | ||
// don't bother padding | ||
return $output; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../../src/Shibalike/Util/UserlandSession.php'; | ||
require __DIR__ . '/../../src/Shibalike/Util/IdGenerator.php'; | ||
|
||
echo Shibalike\Util_UserlandSession::generate_new_id(); | ||
echo Shibalike\Util\IdGenerator::generateBase32Id(); |
Oops, something went wrong.