2 namespace TYPO3\CMS\Saltedpasswords\Salt
;
4 /***************************************************************
7 * (c) 2009-2013 Marcus Krause <marcus#exp2009@t3sec.info>
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
30 * Contains class "tx_saltedpasswords_salts_factory"
31 * that provides a salted hashing method factory.
34 * Class that implements Blowfish salted hashing based on PHP's
37 * @author Marcus Krause <marcus#exp2009@t3sec.info>
43 * An instance of the salted hashing method.
44 * This member is set in the getSaltingInstance() function.
46 * @var \TYPO3\CMS\Saltedpasswords\Salt\AbstractSalt
48 static protected $instance = NULL;
51 * Obtains a salting hashing method instance.
53 * This function will return an instance of a class that implements
54 * tx_saltedpasswords_abstract_salts.
56 * Use parameter NULL to reset the factory!
58 * @param string $saltedHash (optional) Salted hashed password to determine the type of used method from or NULL to reset the factory
59 * @param string $mode (optional) The TYPO3 mode (FE or BE) saltedpasswords shall be used for
60 * @return tx_saltedpasswords_abstract_salts an instance of salting hashing method object
62 static public function getSaltingInstance($saltedHash = '', $mode = TYPO3_MODE
) {
63 // Creating new instance when
64 // * no instance existing
65 // * a salted hash given to determine salted hashing method from
66 // * a NULL parameter given to reset instance back to default method
67 if (!is_object(self
::$instance) ||
!empty($saltedHash) ||
is_NULL($saltedHash)) {
68 // Determine method by checking the given hash
69 if (!empty($saltedHash)) {
70 $result = self
::determineSaltingHashingMethod($saltedHash);
72 self
::$instance = NULL;
75 $classNameToUse = \TYPO3\CMS\Saltedpasswords\Utility\SaltedPasswordsUtility
::getDefaultSaltingHashingMethod($mode);
76 $availableClasses = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/saltedpasswords']['saltMethods'];
77 self
::$instance = \TYPO3\CMS\Core\Utility\GeneralUtility
::getUserObj($availableClasses[$classNameToUse], 'tx_');
80 return self
::$instance;
84 * Method tries to determine the salting hashing method used for given salt.
86 * Method implicitly sets the instance of the found method object in the class property when found.
88 * @param string $saltedHash
89 * @return boolean TRUE, if salting hashing method has been found, otherwise FALSE
91 static public function determineSaltingHashingMethod($saltedHash) {
93 $defaultMethods = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/saltedpasswords']['saltMethods'];
94 foreach ($defaultMethods as $method) {
95 $objectInstance = \TYPO3\CMS\Core\Utility\GeneralUtility
::getUserObj($method, 'tx_');
96 if ($objectInstance instanceof \TYPO3\CMS\Saltedpasswords\Salt\SaltInterface
) {
97 $methodFound = $objectInstance->isValidSaltedPW($saltedHash);
99 self
::$instance = $objectInstance;
108 * Method sets a custom salting hashing method class.
110 * @param string $resource Object resource to use (e.g. 'EXT:saltedpasswords/classes/salts/class.tx_saltedpasswords_salts_blowfish.php:tx_saltedpasswords_salts_blowfish')
111 * @return tx_saltedpasswords_abstract_salts an instance of salting hashing method object
113 static public function setPreferredHashingMethod($resource) {
114 self
::$instance = NULL;
115 $objectInstance = \TYPO3\CMS\Core\Utility\GeneralUtility
::getUserObj($resource);
116 if (is_object($objectInstance) && is_subclass_of($objectInstance, 'TYPO3\\CMS\\Saltedpasswords\\Salt\\AbstractSalt')) {
117 self
::$instance = $objectInstance;
119 return self
::$instance;