3v4l.org

run code in 300+ PHP versions simultaneously
<?php $password = "chemicals1"; $expected = "{SSHA512}w/lHn2LXfNletbfyLVYutBFqUjGPzhmptyleVlehUZSZdylZCt/sDmvkhTBV1Ln4f6rzXTdM6eOGr3LX7FgGCF5/fsbs0vVq"; function generate_postfix_ssha512_hash($password, $salt = false) { $hash_algo = "{SSHA512}"; $salt_length = 8; // generate a random salt if one isn't provided $salt = empty($salt) ? random_bytes($salt_length) : $salt; // hash our password with the salt $hash = hash('sha512', "{$password}{$salt}", true); // base64 encode the salt so we have a sane string $hash = base64_encode("{$hash}{$salt}"); // return our generated password hash with identifier return "{$hash_algo}{$hash}"; } function compare_postfix_ssha512_hash($password, $valid_hash) { $hash_algo = "{SSHA512}"; $salt_length = 8; // strip the identifier from the hash (if exists) $valid_hash = str_replace($hash_algo, "", $valid_hash); // get the salt from the valid hash $salt = substr(base64_decode($valid_hash), -$salt_length); // strip the salt from the end of the valid hash $valid_hash = substr(base64_decode($valid_hash), 0, -$salt_length); // hash our password with the salt $hash = generate_postfix_ssha512_hash($password, $salt); // strip the identifier from the hash (if exists) $hash = str_replace($hash_algo, "", $hash); // strip the salt from the end of the valid hash $hash = substr(base64_decode($hash), 0, -$salt_length); // return the comparison return hash_equals($valid_hash, $hash); } var_dump(compare_postfix_ssha512_hash($password, $expected));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8qtW0
function name:  (null)
number of ops:  10
compiled vars:  !0 = $password, !1 = $expected
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'chemicals1'
    4     1        ASSIGN                                                   !1, '%7BSSHA512%7Dw%2FlHn2LXfNletbfyLVYutBFqUjGPzhmptyleVlehUZSZdylZCt%2FsDmvkhTBV1Ln4f6rzXTdM6eOGr3LX7FgGCF5%2Ffsbs0vVq'
   49     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'compare_postfix_ssha512_hash'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function generate_postfix_ssha512_hash:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8qtW0
function name:  generate_postfix_ssha512_hash
number of ops:  31
compiled vars:  !0 = $password, !1 = $salt, !2 = $hash_algo, !3 = $salt_length, !4 = $hash
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
    7     2        ASSIGN                                                   !2, '%7BSSHA512%7D'
    8     3        ASSIGN                                                   !3, 8
   11     4        ISSET_ISEMPTY_CV                                         !1
          5      > JMPZ                                                     ~7, ->11
          6    >   INIT_FCALL                                               'random_bytes'
          7        SEND_VAR                                                 !3
          8        DO_ICALL                                         $8      
          9        QM_ASSIGN                                        ~9      $8
         10      > JMP                                                      ->12
         11    >   QM_ASSIGN                                        ~9      !1
         12    >   ASSIGN                                                   !1, ~9
   14    13        INIT_FCALL                                               'hash'
         14        SEND_VAL                                                 'sha512'
         15        NOP                                                      
         16        FAST_CONCAT                                      ~11     !0, !1
         17        SEND_VAL                                                 ~11
         18        SEND_VAL                                                 <true>
         19        DO_ICALL                                         $12     
         20        ASSIGN                                                   !4, $12
   17    21        INIT_FCALL                                               'base64_encode'
         22        NOP                                                      
         23        FAST_CONCAT                                      ~14     !4, !1
         24        SEND_VAL                                                 ~14
         25        DO_ICALL                                         $15     
         26        ASSIGN                                                   !4, $15
   20    27        NOP                                                      
         28        FAST_CONCAT                                      ~17     !2, !4
         29      > RETURN                                                   ~17
   21    30*     > RETURN                                                   null

End of function generate_postfix_ssha512_hash

Function compare_postfix_ssha512_hash:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8qtW0
function name:  compare_postfix_ssha512_hash
number of ops:  56
compiled vars:  !0 = $password, !1 = $valid_hash, !2 = $hash_algo, !3 = $salt_length, !4 = $salt, !5 = $hash
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   24     2        ASSIGN                                                   !2, '%7BSSHA512%7D'
   25     3        ASSIGN                                                   !3, 8
   28     4        INIT_FCALL                                               'str_replace'
          5        SEND_VAR                                                 !2
          6        SEND_VAL                                                 ''
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $8      
          9        ASSIGN                                                   !1, $8
   31    10        INIT_FCALL                                               'substr'
         11        INIT_FCALL                                               'base64_decode'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $10     
         14        SEND_VAR                                                 $10
         15        MUL                                              ~11     !3, -1
         16        SEND_VAL                                                 ~11
         17        DO_ICALL                                         $12     
         18        ASSIGN                                                   !4, $12
   34    19        INIT_FCALL                                               'substr'
         20        INIT_FCALL                                               'base64_decode'
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                         $14     
         23        SEND_VAR                                                 $14
         24        SEND_VAL                                                 0
         25        MUL                                              ~15     !3, -1
         26        SEND_VAL                                                 ~15
         27        DO_ICALL                                         $16     
         28        ASSIGN                                                   !1, $16
   37    29        INIT_FCALL                                               'generate_postfix_ssha512_hash'
         30        SEND_VAR                                                 !0
         31        SEND_VAR                                                 !4
         32        DO_FCALL                                      0  $18     
         33        ASSIGN                                                   !5, $18
   40    34        INIT_FCALL                                               'str_replace'
         35        SEND_VAR                                                 !2
         36        SEND_VAL                                                 ''
         37        SEND_VAR                                                 !5
         38        DO_ICALL                                         $20     
         39        ASSIGN                                                   !5, $20
   43    40        INIT_FCALL                                               'substr'
         41        INIT_FCALL                                               'base64_decode'
         42        SEND_VAR                                                 !5
         43        DO_ICALL                                         $22     
         44        SEND_VAR                                                 $22
         45        SEND_VAL                                                 0
         46        MUL                                              ~23     !3, -1
         47        SEND_VAL                                                 ~23
         48        DO_ICALL                                         $24     
         49        ASSIGN                                                   !5, $24
   46    50        INIT_FCALL                                               'hash_equals'
         51        SEND_VAR                                                 !1
         52        SEND_VAR                                                 !5
         53        DO_ICALL                                         $26     
         54      > RETURN                                                   $26
   47    55*     > RETURN                                                   null

End of function compare_postfix_ssha512_hash

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.92 ms | 1407 KiB | 31 Q