OXID eShop CE  4.9.8
 All Classes Files Functions Variables Pages
oxpasswordsaltgenerator.php
Go to the documentation of this file.
1 <?php
2 
8 {
9 
14 
20  public function __construct(oxOpenSSLFunctionalityChecker $openSSLFunctionalityChecker)
21  {
22  $this->_openSSLFunctionalityChecker = $openSSLFunctionalityChecker;
23  }
24 
31  public function generate()
32  {
33  if ($this->_getOpenSSLFunctionalityChecker()->isOpenSslRandomBytesGeneratorAvailable()) {
34  $sSalt = bin2hex(openssl_random_pseudo_bytes(16));
35  } else {
36  $sSalt = $this->_customSaltGenerator();
37  }
38 
39  return $sSalt;
40  }
41 
47  protected function _getOpenSSLFunctionalityChecker()
48  {
50  }
51 
57  protected function _customSaltGenerator()
58  {
59  $sHash = '';
60  $sSalt = '';
61  for ($i = 0; $i < 32; $i++) {
62  $sHash = hash('sha256', $sHash . mt_rand());
63  $iPosition = mt_rand(0, 62);
64  $sSalt .= $sHash[$iPosition];
65  }
66 
67  return $sSalt;
68  }
69 }