TYPO3 CMS  TYPO3_6-2
SaltFactory.php
Go to the documentation of this file.
1 <?php
3 
23 class SaltFactory {
24 
31  static protected $instance = NULL;
32 
39  static public function getRegisteredSaltedHashingMethods() {
40  $saltMethods = static::getDefaultSaltMethods();
41  if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/saltedpasswords']['saltMethods'])) {
42  $configuredMethods = (array)$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/saltedpasswords']['saltMethods'];
43  if (count($configuredMethods) > 0) {
44  if (isset($configuredMethods[0])) {
45  // ensure the key of the array is not numeric, but a class name
46  foreach ($configuredMethods as $method) {
47  $saltMethods[$method] = $method;
48  }
49  } else {
50  $saltMethods = array_merge($saltMethods, $configuredMethods);
51  }
52  }
53  }
54  return $saltMethods;
55  }
56 
62  static protected function getDefaultSaltMethods() {
63  return array(
64  'TYPO3\\CMS\\Saltedpasswords\\Salt\\Md5Salt' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\Md5Salt',
65  'TYPO3\\CMS\\Saltedpasswords\\Salt\\BlowfishSalt' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\BlowfishSalt',
66  'TYPO3\\CMS\\Saltedpasswords\\Salt\\PhpassSalt' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\PhpassSalt'
67  );
68  }
69 
70 
83  static public function getSaltingInstance($saltedHash = '', $mode = TYPO3_MODE) {
84  // Creating new instance when
85  // * no instance existing
86  // * a salted hash given to determine salted hashing method from
87  // * a NULL parameter given to reset instance back to default method
88  if (!is_object(self::$instance) || !empty($saltedHash) || $saltedHash === NULL) {
89  // Determine method by checking the given hash
90  if (!empty($saltedHash)) {
91  $result = self::determineSaltingHashingMethod($saltedHash, $mode);
92  if (!$result) {
93  self::$instance = NULL;
94  }
95  } else {
97  $availableClasses = static::getRegisteredSaltedHashingMethods();
98  self::$instance = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($availableClasses[$classNameToUse]);
99  }
100  }
101  return self::$instance;
102  }
103 
113  static public function determineSaltingHashingMethod($saltedHash, $mode = TYPO3_MODE) {
114  $registeredMethods = static::getRegisteredSaltedHashingMethods();
116  $defaultReference = $registeredMethods[$defaultClassName];
117  unset($registeredMethods[$defaultClassName]);
118  // place the default method first in the order
119  $registeredMethods = array($defaultClassName => $defaultReference) + $registeredMethods;
120  $methodFound = FALSE;
121  foreach ($registeredMethods as $method) {
122  $objectInstance = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($method);
123  if ($objectInstance instanceof SaltInterface) {
124  $methodFound = $objectInstance->isValidSaltedPW($saltedHash);
125  if ($methodFound) {
126  self::$instance = $objectInstance;
127  break;
128  }
129  }
130  }
131  return $methodFound;
132  }
133 
140  static public function setPreferredHashingMethod($resource) {
141  self::$instance = NULL;
142  $objectInstance = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($resource);
143  if (is_object($objectInstance) && is_subclass_of($objectInstance, 'TYPO3\\CMS\\Saltedpasswords\\Salt\\AbstractSalt')) {
144  self::$instance = $objectInstance;
145  }
146  return self::$instance;
147  }
148 }
static determineSaltingHashingMethod($saltedHash, $mode=TYPO3_MODE)
static getSaltingInstance($saltedHash='', $mode=TYPO3_MODE)
Definition: SaltFactory.php:83
const TYPO3_MODE
Definition: init.php:40
static getUserObj($classRef, $checkPrefix='', $silent=FALSE)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]