2 namespace TYPO3\CMS\Saltedpasswords\Utility
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
18 * General library class.
20 * @author Marcus Krause <marcus#exp2009@t3sec.info>
21 * @author Steffen Ritter <info@rs-websystems.de>
23 class SaltedPasswordsUtility
{
26 * Keeps this extension's key.
28 const EXTKEY
= 'saltedpasswords';
31 * Calculates number of backend users, who have no saltedpasswords
36 static public function getNumberOfBackendUsersWithInsecurePassword() {
37 $userCount = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
41 . ' AND password NOT LIKE ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('$%', 'be_users')
42 . ' AND password NOT LIKE ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('M$%', 'be_users')
48 * Returns extension configuration data from $TYPO3_CONF_VARS (configurable in Extension Manager)
50 * @author Rainer Kuhn <kuhn@punkt.de>
51 * @author Marcus Krause <marcus#exp2009@t3sec.info>
52 * @param string $mode TYPO3_MODE, whether Configuration for Frontend or Backend should be delivered
53 * @return array Extension configuration data
55 static public function returnExtConf($mode = TYPO3_MODE
) {
56 $currentConfiguration = self
::returnExtConfDefaults();
57 if (isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['saltedpasswords'])) {
58 $extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['saltedpasswords']);
59 // Merge default configuration with modified configuration:
60 if (isset($extensionConfiguration[$mode . '.'])) {
61 $currentConfiguration = array_merge($currentConfiguration, $extensionConfiguration[$mode . '.']);
64 return $currentConfiguration;
68 * Hook function for felogin "forgotPassword" functionality
69 * encrypts the new password before storing in database
71 * @param array $params Parameter the hook delivers
72 * @param \TYPO3\CMS\Felogin\Controller\FrontendLoginController $pObj Parent Object from which the hook is called
75 public function feloginForgotPasswordHook(array &$params, \TYPO3\CMS\Felogin\Controller\FrontendLoginController
$pObj) {
76 if (self
::isUsageEnabled('FE')) {
77 $objInstanceSaltedPW = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory
::getSaltingInstance();
78 $params['newPassword'] = $objInstanceSaltedPW->getHashedPassword($params['newPassword']);
83 * Returns default configuration of this extension.
85 * @return array Default extension configuration data for localconf.php
87 static public function returnExtConfDefaults() {
89 'onlyAuthService' => '0',
91 'updatePasswd' => '1',
92 'saltedPWHashingMethod' => \TYPO3\CMS\Saltedpasswords\Salt\PhpassSalt
::class,
98 * Function determines the default(=configured) type of
99 * salted hashing method to be used.
101 * @param string $mode (optional) The TYPO3 mode (FE or BE) saltedpasswords shall be used for
102 * @return string Classname of object to be used
104 static public function getDefaultSaltingHashingMethod($mode = TYPO3_MODE
) {
105 $extConf = self
::returnExtConf($mode);
106 $classNameToUse = \TYPO3\CMS\Saltedpasswords\Salt\Md5Salt
::class;
107 if (in_array($extConf['saltedPWHashingMethod'], array_keys(\TYPO3\CMS\Saltedpasswords\Salt\SaltFactory
::getRegisteredSaltedHashingMethods()))) {
108 $classNameToUse = $extConf['saltedPWHashingMethod'];
110 return $classNameToUse;
114 * Returns information if salted password hashes are
115 * indeed used in the TYPO3_MODE.
117 * @param string $mode (optional) The TYPO3 mode (FE or BE) saltedpasswords shall be used for
118 * @return bool TRUE, if salted password hashes are used in the TYPO3_MODE, otherwise FALSE
120 static public function isUsageEnabled($mode = TYPO3_MODE
) {
121 // Login Security Level Recognition
122 $extConf = self
::returnExtConf($mode);
123 $securityLevel = $GLOBALS['TYPO3_CONF_VARS'][$mode]['loginSecurityLevel'];
126 } elseif ($mode == 'FE' && $extConf['enabled']) {
127 return \TYPO3\CMS\Core\Utility\GeneralUtility
::inList('normal,rsa', $securityLevel);