Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Intermediate commit

  • Loading branch information...
commit ec3116db84f9130245ebd70e8be7c97f5073a447 1 parent a962d70
@tothimre authored
View
10 README.markdown
@@ -1,4 +1,12 @@
-# Info Token
+<pre>
+ ### #######
+ # # # ###### #### # #### # # ###### # #
+ # ## # # # # # # # # # # ## #
+ # # # # ##### # # # # # #### ##### # # #
+ # # # # # # # # # # # # # # # #
+ # # ## # # # # # # # # # # ##
+ ### # # # #### # #### # # ###### # #
+</pre>
[![Build Status](https://travis-ci.org/tothimre/hashids_timestamp_salt.png?branch=master)](https://travis-ci.org/flyingwhale/poc)
View
48 src/InfoToken/HashJugglers/Checker.php
@@ -0,0 +1,48 @@
+<?php
+namespace InfoToken\HashJugglers;
+
+use Hashids\Hashids;
+use InfoToken\Hashers\CheckerInterface;
+use InfoToken\Hashers\HasherContainersInterface;
+use InfoToken\Hashers\Hashids\Hasher\HashidsCrypter;
+
+class Checker implements CheckerInterface
+{
+ public static function check(HasherContainersInterface $hashIdContainers, $stringToCheck)
+ {
+ $hashIds = $hashIdContainers->getHashers();
+ /** @var Hashids $hashId */
+ foreach ($hashIds as $hashId){
+ $hash = $hashId->decrypt($stringToCheck);
+ $broken = self::hashSpecificCheck($hash);
+ if($broken){
+ continue;
+ }
+ if(!empty($hash)){
+ return $hash;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return array
+ */
+ public static function hashSpecificCheck(&$value)
+ {
+ $broken = false;
+ $checkerArray = HashidsCrypter::getCheckerArray();
+ $hashCount = count($checkerArray);
+
+ for ($i = 1; $i <= $hashCount; $i++) {
+ if (array_shift($value) != array_shift($checkerArray)) {
+ $broken = true;
+ break;
+ }
+ else{
+ }
+ }
+ return $broken;
+ }
+
+}
View
4 src/InfoToken/Hashers/Hashids/Factory/HashsidsFactory.php
@@ -25,11 +25,9 @@ public static function getDecryptHashids(HasherConstructorValues $hashidConstruc
* @param TimeInterval $timeinterval
* @return CrypterInterface HashidsCrypter
*/
- public static function getEncryptHashids(HasherConstructorValues $hashidConstructorValues, TimeInterval $timeinterval)
+ public static function getEncryptHashid(HasherConstructorValues $hashidConstructorValues, TimeInterval $timeinterval)
{
$hashid = self::getHashid($hashidConstructorValues, $timeinterval->getIntervalStartTime());
-
-
$crypter = new HashidsCrypter();
$crypter->setCrypter($hashid);
$crypter->setSalt($hashidConstructorValues->getSalt().$timeinterval->getIntervalStartTime());
View
38 src/InfoToken/Hashers/Hashids/HashJugglers/Checker.php
@@ -1,38 +0,0 @@
-<?php
-namespace InfoToken\Hashers\Hashids\HashJugglers;
-
-use Hashids\Hashids;
-use InfoToken\Hashers\CheckerInterface;
-use InfoToken\Hashers\HasherContainersInterface;
-
-class Checker implements CheckerInterface
-{
- public static function check(HasherContainersInterface $hashIdContainers, $stringToCheck)
- {
- $hashIds = $hashIdContainers->getHashers();
- /** @var Hashids $hashId */
- $hash = array();
- foreach ($hashIds as $hashId){
- $hash = $hashId->decrypt($stringToCheck);
- $checkerArray = Creator::getCheckerArray();
- $hashCount = count($checkerArray);
- $broken = false;
- for($i=1;$i<=$hashCount;$i++)
- {
- if(array_shift($hash) != array_shift($checkerArray)){
- $broken = true;
- break;
- }
- }
- if($broken){
- continue;
- }
- if(!empty($hash)){
- return $hash;
- }
- }
- return $hash;
-
- }
-
-}
View
18 src/InfoToken/Hashers/Hashids/HashJugglers/Creator.php
@@ -1,18 +0,0 @@
-<?php
-namespace InfoToken\Hashers\Hashids\HashJugglers;
-
-use InfoToken\Hashers\HasherInterface;
-
-class Creator
-{
- public static function getCheckerArray(){
- return array(
- 123456,789012,345678,901234,567890,
- 123456,789012,345678,901234,567890,
- 123456,789012,345678,901234,567890,
- 123456,789012,345678,901234,567890,
- 123456,789012,345678,901234,567890,
- 123456,789012,345678,901234,5
- );
- }
-}
View
15 src/InfoToken/Hashers/Hashids/Hasher/HashidsCrypter.php
@@ -4,7 +4,7 @@
use Hashids\Hashids;
use InfoToken\Hashers\CrypterInterface;
-use InfoToken\Hashers\Hashids\HashJugglers\Creator;
+use InfoToken\HashJugglers\Creator;
class HashidsCrypter implements CrypterInterface
{
@@ -44,7 +44,7 @@ public function getSalt()
public function encrypt($data)
{
// public static function create(HasherInterface $hashId, $numbersArray)
- $hash = call_user_func_array(array($this->crypter, 'encrypt' ),array_merge(Creator::getCheckerArray(), $data));
+ $hash = call_user_func_array(array($this->crypter, 'encrypt' ),array_merge(self::getCheckerArray(), $data));
return $hash;
return $this->crypter->encrypt($string);
}
@@ -58,6 +58,17 @@ public function decrypt($string)
return $this->crypter->decrypt($string);
}
+ public static function getCheckerArray(){
+ return array(
+ 123456,789012,345678,901234,567890,
+ 123456,789012,345678,901234,567890,
+ 123456,789012,345678,901234,567890,
+ 123456,789012,345678,901234,567890,
+ 123456,789012,345678,901234,567890,
+ 123456,789012,345678,901234,5
+ );
+ }
+
}
View
7 ...oken/Hashids/HashJugglers/CreatorTest.php → tests/InfoToken/HashJugglers/CreatorTest.php
@@ -2,16 +2,17 @@
use InfoToken\Hashers\Hashids\Factory\HashsidsFactory;
use InfoToken\Hashers\Hashids\HasherConstructorValues;
use InfoToken\TimeInterval;
-use InfoToken\Hashers\Hashids\HashJugglers\Creator;
+use InfoToken\HashJugglers\Creator;
+use InfoToken\Hashers\Hashids\Hasher\HashidsCrypter;
-class CreatorTest extends \PHPUnit_Framework_TestCase
+class HashidsCrypterTest extends \PHPUnit_Framework_TestCase
{
const DEF_INTERVAL = 5;
public function testCreate(){
$HashidsConstructorValues = new HasherConstructorValues();
$interval = new TimeInterval(self::DEF_INTERVAL);
- $hasher = HashsidsFactory::getEncryptHashids($HashidsConstructorValues, $interval);
+ $hasher = HashsidsFactory::getEncryptHashid($HashidsConstructorValues, $interval);
$hash = $hasher->encrypt(array(123456, 123457, 123458));
$this->assertNotEquals('', $hash);
}
View
6 ...oken/Hashids/HashJugglers/CheckerTest.php → ...ken/Hashids/Hasher/HashidsCrypterTest.php
@@ -3,8 +3,8 @@
use InfoToken\Hashers\Hashids\Factory\HashsidsFactory;
use InfoToken\Hashers\Hashids\HasherConstructorValues;
use InfoToken\TimeInterval;
-use InfoToken\Hashers\Hashids\HashJugglers\Checker;
-use InfoToken\Hashers\Hashids\HashJugglers\Creator;
+use InfoToken\HashJugglers\Checker;
+use InfoToken\HashJugglers\Creator;
class checkerTest extends \PHPUnit_Framework_TestCase
{
@@ -26,7 +26,7 @@ public function testCreate(){
$HashidsConstructorValues = new HasherConstructorValues();
$interval = new TimeInterval(self::DEF_INTERVAL);
$interval->setCurrentTimestamp($baseTimestamp + $startTimeShift);
- $hasher = HashsidsFactory::getEncryptHashids($HashidsConstructorValues, $interval);
+ $hasher = HashsidsFactory::getEncryptHashid($HashidsConstructorValues, $interval);
$hash = $hasher->encrypt(array($testNumber,$testNumber+1));
$checkerInterval = new TimeInterval(self::DEF_INTERVAL);
Please sign in to comment.
Something went wrong with that request. Please try again.