3v4l.org

run code in 500+ 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:  41
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        FRAMELESS_ICALL_3                str_replace         ~8      !2, ''
          5        OP_DATA                                                      !1
          6        ASSIGN                                                       !1, ~8
   31     7        INIT_FCALL                                                   'base64_decode'
          8        SEND_VAR                                                     !1
          9        DO_ICALL                                             $10     
         10        MUL                                                  ~11     !3, -1
         11        FRAMELESS_ICALL_2                substr              ~12     $10, ~11
         12        ASSIGN                                                       !4, ~12
   34    13        INIT_FCALL                                                   'base64_decode'
         14        SEND_VAR                                                     !1
         15        DO_ICALL                                             $14     
         16        MUL                                                  ~15     !3, -1
         17        FRAMELESS_ICALL_3                substr              ~16     $14, 0
         18        OP_DATA                                                      ~15
         19        ASSIGN                                                       !1, ~16
   37    20        INIT_FCALL                                                   'generate_postfix_ssha512_hash'
         21        SEND_VAR                                                     !0
         22        SEND_VAR                                                     !4
         23        DO_FCALL                                          0  $18     
         24        ASSIGN                                                       !5, $18
   40    25        FRAMELESS_ICALL_3                str_replace         ~20     !2, ''
         26        OP_DATA                                                      !5
         27        ASSIGN                                                       !5, ~20
   43    28        INIT_FCALL                                                   'base64_decode'
         29        SEND_VAR                                                     !5
         30        DO_ICALL                                             $22     
         31        MUL                                                  ~23     !3, -1
         32        FRAMELESS_ICALL_3                substr              ~24     $22, 0
         33        OP_DATA                                                      ~23
         34        ASSIGN                                                       !5, ~24
   46    35        INIT_FCALL                                                   'hash_equals'
         36        SEND_VAR                                                     !1
         37        SEND_VAR                                                     !5
         38        DO_ICALL                                             $26     
         39      > RETURN                                                       $26
   47    40*     > RETURN                                                       null

End of function compare_postfix_ssha512_hash

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
163.98 ms | 2130 KiB | 21 Q