Blame view

src/lib/common.php 2.11 KB
ef60cd4d   Administrator   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  <?php
  
  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  
  namespace 
  {
      /**
       * common
       *
       * @author      Roman Telychko
       * @version     0.1.20130712
       *
       */
      class common
      {
          /////////////////////////////////////////////////////////////////////////////
      
          /**
           * common::hashPasswd()
           *
           * @author      Roman Telychko
           * @version     3.0.20131010
           *
           * @param     string      $passwd
           * @return    string      $hash
           */
          public function hashPasswd( $passwd )
          {
              $salt1 = 'IKudI9k4sts40Spu1yAwcxeaD7umJ8aMAYt6Uj862VTHBh55sMi7DPRkvgckXK88ecj6aDy1Q0DYB28ZVuygR6rlqFoRFcKn45XT5gzbADbzNfBHxMgUmEnb79CyFx7O';            # pwgen -s 128
              $salt2 = 'JzbdFHvuEamXvr8jXWCHkoRqXwEQE86NwPH27vxsdp7T3ln1rk2Mbtu9ADAUIgxpDePe9jzT0KpQceQLTFMSl1fZjmYIl1jbRtlNcuFjUaHy5X0FE55MpT8Kf2xZZnGI';            # pwgen -s 128
  
              $hash = '//'.$salt1.'//'.base64_encode( $passwd ).'//';
              $pieces = str_split( $salt2, 10 );
  
              for( $i=0; $i<10000; $i++ )
              {
                  $hash = hash( 'sha512', $pieces[( $i % 10 )].'|'.$hash );
              }
  
              return $hash;
          }
  
  
          public function array_column( $arr, $column_key, $index_key = null )
          {
              if( empty($arr) )
              {
                  return [];
              }
  
              $data   = [];
              $c      = 0;
  
              foreach( $arr as $a )
              {
                  if( isset($a[$column_key]) )
                  {
                      $data[ ( !empty($index_key) && isset($a[$index_key]) ) ? $a[$index_key] : $c ] = $a[$column_key];
                      $c++;
                  }
              }
  
              return $data;
          }
      
          /////////////////////////////////////////////////////////////////////////////
      }
  }
  
  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////