Permalink
Browse files

Intermediate commit

  • Loading branch information...
1 parent a962d70 commit e70b3a241c4f8c2d41a6660d916d5b00c659b609 @tothimre committed Jan 8, 2014
@@ -4,35 +4,45 @@
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 */
- $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;
- }
- }
+ $broken = self::hashSpecificCheck($hash);
if($broken){
continue;
}
if(!empty($hash)){
return $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;
}
}
@@ -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
- );
- }
-}
@@ -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
+ );
+ }
+
}

0 comments on commit e70b3a2

Please sign in to comment.