3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getCryptedPassword($plaintext, $salt = '', $encryption = 'crypt-blowfish', $show_encrypt = false) { // mimic the getSalt function so we can use it in the example. if ($salt) { $salt = substr(preg_replace('|^{crypt}|i', '', $salt), 0, 16); } else { if (function_exists('random_bytes')) { $salt = '$2$' . substr(md5(random_bytes(16)), 0, 12) . '$'; } else { // Fake the salt result (a previously generated salt using https://github.com/paragonie/random_compat ) $salt = '$2$9936b047ea8b$'; } } // Encrypt the password. switch ($encryption) { case 'plain': return $plaintext; case 'sha': $encrypted = base64_encode(mhash(MHASH_SHA1, $plaintext)); return ($show_encrypt) ? '{SHA}' . $encrypted : $encrypted; case 'crypt': case 'crypt-des': case 'crypt-md5': case 'crypt-blowfish': return ($show_encrypt ? '{crypt}' : '') . crypt($plaintext, $salt); case 'md5-hex': default: $encrypted = ($salt) ? md5($plaintext . $salt) : md5($plaintext); return ($show_encrypt) ? '{MD5}' . $encrypted : $encrypted; } } $plaintext = 'mySuperSecretPassword'; if (function_exists('random_bytes')) { $salt = '$2$' . substr(md5(random_bytes(16)), 0, 12) . '$'; //$salt = '$2y$09$anexampl$'; } else { // Fake the salt result (a randomly created salt using https://github.com/paragonie/random_compat ) // $salt = '$2$9936b047ea8b$'; $salt = '$2y$09$anexampl$'; } echo 'salt length = ' . strlen($salt) . "\n"; echo strlen(crypt($plaintext, $salt)) . "\n"; echo crypt('U*U', '$2a$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW') . "\n"; echo crypt($plaintext, $salt) . "\n"; echo strlen(getCryptedPassword($plaintext, $salt, 'crypt-blowfish')) . "\n"; echo getCryptedPassword($plaintext, $salt, 'crypt-blowfish');
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Is24j
function name:  (null)
number of ops:  59
compiled vars:  !0 = $plaintext, !1 = $salt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   ASSIGN                                                   !0, 'mySuperSecretPassword'
   42     1        INIT_FCALL                                               'function_exists'
          2        SEND_VAL                                                 'random_bytes'
          3        DO_ICALL                                         $3      
          4      > JMPZ                                                     $3, ->20
   44     5    >   INIT_FCALL                                               'substr'
          6        INIT_FCALL                                               'md5'
          7        INIT_FCALL                                               'random_bytes'
          8        SEND_VAL                                                 16
          9        DO_ICALL                                         $4      
         10        SEND_VAR                                                 $4
         11        DO_ICALL                                         $5      
         12        SEND_VAR                                                 $5
         13        SEND_VAL                                                 0
         14        SEND_VAL                                                 12
         15        DO_ICALL                                         $6      
         16        CONCAT                                           ~7      '%242%24', $6
         17        CONCAT                                           ~8      ~7, '%24'
         18        ASSIGN                                                   !1, ~8
   42    19      > JMP                                                      ->21
   51    20    >   ASSIGN                                                   !1, '%242y%2409%24anexampl%24'
   54    21    >   STRLEN                                           ~11     !1
         22        CONCAT                                           ~12     'salt+length+%3D+', ~11
         23        CONCAT                                           ~13     ~12, '%0A'
         24        ECHO                                                     ~13
   55    25        INIT_FCALL                                               'crypt'
         26        SEND_VAR                                                 !0
         27        SEND_VAR                                                 !1
         28        DO_ICALL                                         $14     
         29        STRLEN                                           ~15     $14
         30        CONCAT                                           ~16     ~15, '%0A'
         31        ECHO                                                     ~16
   56    32        INIT_FCALL                                               'crypt'
         33        SEND_VAL                                                 'U%2AU'
         34        SEND_VAL                                                 '%242a%24CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW'
         35        DO_ICALL                                         $17     
         36        CONCAT                                           ~18     $17, '%0A'
         37        ECHO                                                     ~18
   57    38        INIT_FCALL                                               'crypt'
         39        SEND_VAR                                                 !0
         40        SEND_VAR                                                 !1
         41        DO_ICALL                                         $19     
         42        CONCAT                                           ~20     $19, '%0A'
         43        ECHO                                                     ~20
   58    44        INIT_FCALL                                               'getcryptedpassword'
         45        SEND_VAR                                                 !0
         46        SEND_VAR                                                 !1
         47        SEND_VAL                                                 'crypt-blowfish'
         48        DO_FCALL                                      0  $21     
         49        STRLEN                                           ~22     $21
         50        CONCAT                                           ~23     ~22, '%0A'
         51        ECHO                                                     ~23
   59    52        INIT_FCALL                                               'getcryptedpassword'
         53        SEND_VAR                                                 !0
         54        SEND_VAR                                                 !1
         55        SEND_VAL                                                 'crypt-blowfish'
         56        DO_FCALL                                      0  $24     
         57        ECHO                                                     $24
         58      > RETURN                                                   1

Function getcryptedpassword:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 17
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
9 jumps found. (Code = 188) Position 1 = 53, Position 2 = 54, Position 3 = 69, Position 4 = 69, Position 5 = 69, Position 6 = 69, Position 7 = 79, Position 8 = 79, Position 9 = 38
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 67
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 67
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 69
2 jumps found. (Code = 43) Position 1 = 70, Position 2 = 72
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 72
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 69
Branch analysis from position: 69
Branch analysis from position: 69
Branch analysis from position: 79
2 jumps found. (Code = 43) Position 1 = 80, Position 2 = 86
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 90
Branch analysis from position: 90
2 jumps found. (Code = 43) Position 1 = 92, Position 2 = 95
Branch analysis from position: 92
1 jumps found. (Code = 42) Position 1 = 96
Branch analysis from position: 96
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 95
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 86
2 jumps found. (Code = 43) Position 1 = 92, Position 2 = 95
Branch analysis from position: 92
Branch analysis from position: 95
Branch analysis from position: 79
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 53
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 54
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 69
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 69
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 48, Position 2 = 69
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 69
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 79
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 79
Branch analysis from position: 79
Branch analysis from position: 79
Branch analysis from position: 69
Branch analysis from position: 69
Branch analysis from position: 69
Branch analysis from position: 69
Branch analysis from position: 54
Branch analysis from position: 53
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 36
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 36
9 jumps found. (Code = 188) Position 1 = 53, Position 2 = 54, Position 3 = 69, Position 4 = 69, Position 5 = 69, Position 6 = 69, Position 7 = 79, Position 8 = 79, Position 9 = 38
Branch analysis from position: 53
Branch analysis from position: 54
Branch analysis from position: 69
Branch analysis from position: 69
Branch analysis from position: 69
Branch analysis from position: 69
Branch analysis from position: 79
Branch analysis from position: 79
Branch analysis from position: 38
filename:       /in/Is24j
function name:  getCryptedPassword
number of ops:  98
compiled vars:  !0 = $plaintext, !1 = $salt, !2 = $encryption, !3 = $show_encrypt, !4 = $encrypted
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      ''
          2        RECV_INIT                                        !2      'crypt-blowfish'
          3        RECV_INIT                                        !3      <false>
    5     4      > JMPZ                                                     !1, ->17
    7     5    >   INIT_FCALL                                               'substr'
          6        INIT_FCALL                                               'preg_replace'
          7        SEND_VAL                                                 '%7C%5E%7Bcrypt%7D%7Ci'
          8        SEND_VAL                                                 ''
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $5      
         11        SEND_VAR                                                 $5
         12        SEND_VAL                                                 0
         13        SEND_VAL                                                 16
         14        DO_ICALL                                         $6      
         15        ASSIGN                                                   !1, $6
    5    16      > JMP                                                      ->37
   11    17    >   INIT_FCALL                                               'function_exists'
         18        SEND_VAL                                                 'random_bytes'
         19        DO_ICALL                                         $8      
         20      > JMPZ                                                     $8, ->36
   13    21    >   INIT_FCALL                                               'substr'
         22        INIT_FCALL                                               'md5'
         23        INIT_FCALL                                               'random_bytes'
         24        SEND_VAL                                                 16
         25        DO_ICALL                                         $9      
         26        SEND_VAR                                                 $9
         27        DO_ICALL                                         $10     
         28        SEND_VAR                                                 $10
         29        SEND_VAL                                                 0
         30        SEND_VAL                                                 12
         31        DO_ICALL                                         $11     
         32        CONCAT                                           ~12     '%242%24', $11
         33        CONCAT                                           ~13     ~12, '%24'
         34        ASSIGN                                                   !1, ~13
   11    35      > JMP                                                      ->37
   18    36    >   ASSIGN                                                   !1, '%242%249936b047ea8b%24'
   22    37    > > SWITCH_STRING                                            !2, [ 'plain':->53, 'sha':->54, 'crypt':->69, 'crypt-des':->69, 'crypt-md5':->69, 'crypt-blowfish':->69, 'md5-hex':->79, ], ->79
   24    38    >   IS_EQUAL                                                 !2, 'plain'
         39      > JMPNZ                                                    ~16, ->53
   26    40    >   IS_EQUAL                                                 !2, 'sha'
         41      > JMPNZ                                                    ~16, ->54
   29    42    >   IS_EQUAL                                                 !2, 'crypt'
         43      > JMPNZ                                                    ~16, ->69
   30    44    >   IS_EQUAL                                                 !2, 'crypt-des'
         45      > JMPNZ                                                    ~16, ->69
   31    46    >   IS_EQUAL                                                 !2, 'crypt-md5'
         47      > JMPNZ                                                    ~16, ->69
   32    48    >   IS_EQUAL                                                 !2, 'crypt-blowfish'
         49      > JMPNZ                                                    ~16, ->69
   34    50    >   IS_EQUAL                                                 !2, 'md5-hex'
         51      > JMPNZ                                                    ~16, ->79
         52    > > JMP                                                      ->79
   25    53    > > RETURN                                                   !0
   27    54    >   INIT_FCALL                                               'base64_encode'
         55        INIT_FCALL_BY_NAME                                       'mhash'
         56        FETCH_CONSTANT                                   ~17     'MHASH_SHA1'
         57        SEND_VAL_EX                                              ~17
         58        SEND_VAR_EX                                              !0
         59        DO_FCALL                                      0  $18     
         60        SEND_VAR                                                 $18
         61        DO_ICALL                                         $19     
         62        ASSIGN                                                   !4, $19
   28    63      > JMPZ                                                     !3, ->67
         64    >   CONCAT                                           ~21     '%7BSHA%7D', !4
         65        QM_ASSIGN                                        ~22     ~21
         66      > JMP                                                      ->68
         67    >   QM_ASSIGN                                        ~22     !4
         68    > > RETURN                                                   ~22
   33    69    > > JMPZ                                                     !3, ->72
         70    >   QM_ASSIGN                                        ~23     '%7Bcrypt%7D'
         71      > JMP                                                      ->73
         72    >   QM_ASSIGN                                        ~23     ''
         73    >   INIT_FCALL                                               'crypt'
         74        SEND_VAR                                                 !0
         75        SEND_VAR                                                 !1
         76        DO_ICALL                                         $24     
         77        CONCAT                                           ~25     ~23, $24
         78      > RETURN                                                   ~25
   36    79    > > JMPZ                                                     !1, ->86
         80    >   INIT_FCALL                                               'md5'
         81        CONCAT                                           ~26     !0, !1
         82        SEND_VAL                                                 ~26
         83        DO_ICALL                                         $27     
         84        QM_ASSIGN                                        ~28     $27
         85      > JMP                                                      ->90
         86    >   INIT_FCALL                                               'md5'
         87        SEND_VAR                                                 !0
         88        DO_ICALL                                         $29     
         89        QM_ASSIGN                                        ~28     $29
         90    >   ASSIGN                                                   !4, ~28
   37    91      > JMPZ                                                     !3, ->95
         92    >   CONCAT                                           ~31     '%7BMD5%7D', !4
         93        QM_ASSIGN                                        ~32     ~31
         94      > JMP                                                      ->96
         95    >   QM_ASSIGN                                        ~32     !4
         96    > > RETURN                                                   ~32
   39    97*     > RETURN                                                   null

End of function getcryptedpassword

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
133.92 ms | 1479 KiB | 22 Q