ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
WhiteHat101\Crypt\APR1_MD5 Class Reference
+ Collaboration diagram for WhiteHat101\Crypt\APR1_MD5:

Static Public Member Functions

static hash ($mdp, $salt=null)
 
static salt ()
 
static check ($plain, $hash)
 

Data Fields

const BASE64_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
 
const APRMD5_ALPHABET = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
 

Detailed Description

Definition at line 5 of file APR1_MD5.php.

Member Function Documentation

◆ check()

static WhiteHat101\Crypt\APR1_MD5::check (   $plain,
  $hash 
)
static

Definition at line 63 of file APR1_MD5.php.

References GuzzleHttp\Psr7\hash().

63  {
64  $parts = explode('$', $hash);
65  return self::hash($plain, $parts[2]) === $hash;
66  }
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.
Definition: functions.php:406
+ Here is the call graph for this function:

◆ hash()

static WhiteHat101\Crypt\APR1_MD5::hash (   $mdp,
  $salt = null 
)
static

Definition at line 17 of file APR1_MD5.php.

References $i, and $new.

17  {
18  if (is_null($salt))
19  $salt = self::salt();
20  $salt = substr($salt, 0, 8);
21  $max = strlen($mdp);
22  $context = $mdp.'$apr1$'.$salt;
23  $binary = pack('H32', md5($mdp.$salt.$mdp));
24  for($i=$max; $i>0; $i-=16)
25  $context .= substr($binary, 0, min(16, $i));
26  for($i=$max; $i>0; $i>>=1)
27  $context .= ($i & 1) ? chr(0) : $mdp[0];
28  $binary = pack('H32', md5($context));
29  for($i=0; $i<1000; $i++) {
30  $new = ($i & 1) ? $mdp : $binary;
31  if($i % 3) $new .= $salt;
32  if($i % 7) $new .= $mdp;
33  $new .= ($i & 1) ? $binary : $mdp;
34  $binary = pack('H32', md5($new));
35  }
36  $hash = '';
37  for ($i = 0; $i < 5; $i++) {
38  $k = $i+6;
39  $j = $i+12;
40  if($j == 16) $j = 5;
41  $hash = $binary[$i].$binary[$k].$binary[$j].$hash;
42  }
43  $hash = chr(0).chr(0).$binary[11].$hash;
44  $hash = strtr(
45  strrev(substr(base64_encode($hash), 2)),
46  self::BASE64_ALPHABET,
47  self::APRMD5_ALPHABET
48  );
49  return '$apr1$'.$salt.'$'.$hash;
50  }
$i
Definition: disco.tpl.php:19

◆ salt()

static WhiteHat101\Crypt\APR1_MD5::salt ( )
static

Definition at line 53 of file APR1_MD5.php.

References $i.

53  {
54  $alphabet = self::APRMD5_ALPHABET;
55  $salt = '';
56  for($i=0; $i<8; $i++) {
57  $offset = hexdec(bin2hex(openssl_random_pseudo_bytes(1))) % 64;
58  $salt .= $alphabet[$offset];
59  }
60  return $salt;
61  }
$i
Definition: disco.tpl.php:19

Field Documentation

◆ APRMD5_ALPHABET

const WhiteHat101\Crypt\APR1_MD5::APRMD5_ALPHABET = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'

Definition at line 8 of file APR1_MD5.php.

◆ BASE64_ALPHABET

const WhiteHat101\Crypt\APR1_MD5::BASE64_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'

Definition at line 7 of file APR1_MD5.php.


The documentation for this class was generated from the following file: