OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxpasswordsaltgenerator.php
Go to the documentation of this file.
1 <?php
2 
8 {
13 
17  public function __construct(oxOpenSSLFunctionalityChecker $openSSLFunctionalityChecker)
18  {
19  $this->_openSSLFunctionalityChecker = $openSSLFunctionalityChecker;
20  }
21 
28  public function generate()
29  {
30  if ($this->_getOpenSSLFunctionalityChecker()->isOpenSslRandomBytesGeneratorAvailable()) {
31  $sSalt = bin2hex(openssl_random_pseudo_bytes(16));
32  } else {
33  $sSalt = $this->_customSaltGenerator();
34  }
35 
36  return $sSalt;
37  }
38 
42  protected function _getOpenSSLFunctionalityChecker()
43  {
45  }
46 
50  protected function _customSaltGenerator()
51  {
52  $sHash = '';
53  $sSalt = '';
54  for ($i = 0; $i < 32; $i++) {
55  $sHash = hash('sha256', $sHash . mt_rand());
56  $iPosition = mt_rand(0, 62);
57  $sSalt .= $sHash[$iPosition];
58  }
59 
60  return $sSalt;
61  }
62 }