TYPO3  7.6
Evaluator.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Saltedpasswords\Evaluation;
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  */
16 
21 class Evaluator
22 {
30  protected $mode = null;
31 
38  public function returnFieldJS()
39  {
40  return 'return value;';
41  }
42 
51  public function evaluateFieldValue($value, $is_in, &$set)
52  {
53  $isEnabled = $this->mode ? \TYPO3\CMS\Saltedpasswords\Utility\SaltedPasswordsUtility::isUsageEnabled($this->mode) : \TYPO3\CMS\Saltedpasswords\Utility\SaltedPasswordsUtility::isUsageEnabled();
54  if ($isEnabled) {
55  $isMD5 = preg_match('/[0-9abcdef]{32,32}/', $value);
56  $isDeprecatedSaltedHash = \TYPO3\CMS\Core\Utility\GeneralUtility::inList('C$,M$', substr($value, 0, 2));
58  $objInstanceSaltedPW = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance(null, $this->mode);
59  if ($isMD5) {
60  $set = true;
61  $value = 'M' . $objInstanceSaltedPW->getHashedPassword($value);
62  } else {
63  // Determine method used for the (possibly) salted hashed password
64  $tempValue = $isDeprecatedSaltedHash ? substr($value, 1) : $value;
65  $tempObjInstanceSaltedPW = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance($tempValue);
66  if (!is_object($tempObjInstanceSaltedPW)) {
67  $set = true;
68  $value = $objInstanceSaltedPW->getHashedPassword($value);
69  }
70  }
71  }
72  return $value;
73  }
74 }