TYPO3  7.6
SaltedPasswordsUtility.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Saltedpasswords\Utility;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
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.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
17 
22 {
26  const EXTKEY = 'saltedpasswords';
27 
35  {
36  $userCount = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
37  '*',
38  'be_users',
39  'password != \'\''
40  . ' AND password NOT LIKE ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('$%', 'be_users')
41  . ' AND password NOT LIKE ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('M$%', 'be_users')
42  );
43  return $userCount;
44  }
45 
51  public static function returnExtConf($mode = TYPO3_MODE)
52  {
53  $currentConfiguration = self::returnExtConfDefaults();
54  if (isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['saltedpasswords'])) {
55  $extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['saltedpasswords']);
56  // Merge default configuration with modified configuration:
57  if (isset($extensionConfiguration[$mode . '.'])) {
58  $currentConfiguration = array_merge($currentConfiguration, $extensionConfiguration[$mode . '.']);
59  }
60  }
61  return $currentConfiguration;
62  }
63 
72  public function feloginForgotPasswordHook(array &$params, \TYPO3\CMS\Felogin\Controller\FrontendLoginController $pObj)
73  {
74  if (self::isUsageEnabled('FE')) {
75  $objInstanceSaltedPW = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance();
76  $params['newPassword'] = $objInstanceSaltedPW->getHashedPassword($params['newPassword']);
77  }
78  }
79 
85  public static function returnExtConfDefaults()
86  {
87  return array(
88  'onlyAuthService' => '0',
89  'forceSalted' => '0',
90  'updatePasswd' => '1',
91  'saltedPWHashingMethod' => \TYPO3\CMS\Saltedpasswords\Salt\PhpassSalt::class,
92  'enabled' => '1'
93  );
94  }
95 
103  public static function getDefaultSaltingHashingMethod($mode = TYPO3_MODE)
104  {
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'];
109  }
110  return $classNameToUse;
111  }
112 
120  public static function isUsageEnabled($mode = TYPO3_MODE)
121  {
122  // Login Security Level Recognition
123  $extConf = self::returnExtConf($mode);
124  $securityLevel = trim($GLOBALS['TYPO3_CONF_VARS'][$mode]['loginSecurityLevel']) ?: 'normal';
125  if ($mode === 'BE') {
126  return true;
127  } elseif ($mode === 'FE' && $extConf['enabled']) {
128  return GeneralUtility::inList('normal,rsa', $securityLevel);
129  }
130  return false;
131  }
132 }