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 ***************************************************************/
31 * Class that implements Blowfish salted hashing based on PHP's
34 * @author Marcus Krause <marcus#exp2009@t3sec.info>
39 * An instance of the salted hashing method.
40 * This member is set in the getSaltingInstance() function.
42 * @var \TYPO3\CMS\Saltedpasswords\Salt\AbstractSalt
44 static protected $instance = NULL;
47 * Obtains a salting hashing method instance.
49 * This function will return an instance of a class that implements
50 * \TYPO3\CMS\Saltedpasswords\Salt\AbstractSalt
52 * Use parameter NULL to reset the factory!
54 * @param string $saltedHash (optional) Salted hashed password to determine the type of used method from or NULL to reset the factory
55 * @param string $mode (optional) The TYPO3 mode (FE or BE) saltedpasswords shall be used for
56 * @return \TYPO3\CMS\Saltedpasswords\Salt\AbstractSalt An instance of salting hashing method object
58 static public function getSaltingInstance($saltedHash = '', $mode = TYPO3_MODE
) {
59 // Creating new instance when
60 // * no instance existing
61 // * a salted hash given to determine salted hashing method from
62 // * a NULL parameter given to reset instance back to default method
63 if (!is_object(self
::$instance) ||
!empty($saltedHash) ||
is_NULL($saltedHash)) {
64 // Determine method by checking the given hash
65 if (!empty($saltedHash)) {
66 $result = self
::determineSaltingHashingMethod($saltedHash);
68 self
::$instance = NULL;
71 $classNameToUse = \TYPO3\CMS\Saltedpasswords\Utility\SaltedPasswordsUtility
::getDefaultSaltingHashingMethod($mode);
72 $availableClasses = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/saltedpasswords']['saltMethods'];
73 self
::$instance = \TYPO3\CMS\Core\Utility\GeneralUtility
::getUserObj($availableClasses[$classNameToUse], 'tx_');
76 return self
::$instance;
80 * Method tries to determine the salting hashing method used for given salt.
82 * Method implicitly sets the instance of the found method object in the class property when found.
84 * @param string $saltedHash
85 * @return boolean TRUE, if salting hashing method has been found, otherwise FALSE
87 static public function determineSaltingHashingMethod($saltedHash) {
89 $defaultMethods = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/saltedpasswords']['saltMethods'];
90 foreach ($defaultMethods as $method) {
91 $objectInstance = \TYPO3\CMS\Core\Utility\GeneralUtility
::getUserObj($method, 'tx_');
92 if ($objectInstance instanceof \TYPO3\CMS\Saltedpasswords\Salt\SaltInterface
) {
93 $methodFound = $objectInstance->isValidSaltedPW($saltedHash);
95 self
::$instance = $objectInstance;
104 * Method sets a custom salting hashing method class.
106 * @param string $resource Object resource to use (e.g. 'TYPO3\\CMS\\Saltedpasswords\\Salt\\BlowfishSalt')
107 * @return \TYPO3\CMS\Saltedpasswords\Salt\AbstractSalt An instance of salting hashing method object
109 static public function setPreferredHashingMethod($resource) {
110 self
::$instance = NULL;
111 $objectInstance = \TYPO3\CMS\Core\Utility\GeneralUtility
::getUserObj($resource);
112 if (is_object($objectInstance) && is_subclass_of($objectInstance, 'TYPO3\\CMS\\Saltedpasswords\\Salt\\AbstractSalt')) {
113 self
::$instance = $objectInstance;
115 return self
::$instance;