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) . '$'; } else { // Fake the salt result (a previously generated salt using https://github.com/paragonie/random_compat ) $salt = '$2$9936b047ea8b$'; } echo strlen(crypt($plaintext, $salt)) . "\n"; echo crypt($plaintext, '$2$' . substr(md5(random_bytes(16)), 0, 12) . '$') . "\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/40vi4
function name:  (null)
number of ops:  62
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
         19      > JMP                                                      ->21
   49    20    >   ASSIGN                                                   !1, '%242%249936b047ea8b%24'
   52    21    >   INIT_FCALL                                               'crypt'
         22        SEND_VAR                                                 !0
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                         $11     
         25        STRLEN                                           ~12     $11
         26        CONCAT                                           ~13     ~12, '%0A'
         27        ECHO                                                     ~13
   53    28        INIT_FCALL                                               'crypt'
         29        SEND_VAR                                                 !0
         30        INIT_FCALL                                               'substr'
         31        INIT_FCALL                                               'md5'
         32        INIT_FCALL                                               'random_bytes'
         33        SEND_VAL                                                 16
         34        DO_ICALL                                         $14     
         35        SEND_VAR                                                 $14
         36        DO_ICALL                                         $15     
         37        SEND_VAR                                                 $15
         38        SEND_VAL                                                 0
         39        SEND_VAL                                                 12
         40        DO_ICALL                                         $16     
         41        CONCAT                                           ~17     '%242%24', $16
         42        CONCAT                                           ~18     ~17, '%24'
         43        SEND_VAL                                                 ~18
         44        DO_ICALL                                         $19     
         45        CONCAT                                           ~20     $19, '%0A'
         46        ECHO                                                     ~20
   54    47        INIT_FCALL                                               'getcryptedpassword'
         48        SEND_VAR                                                 !0
         49        SEND_VAR                                                 !1
         50        SEND_VAL                                                 'crypt-blowfish'
         51        DO_FCALL                                      0  $21     
         52        STRLEN                                           ~22     $21
         53        CONCAT                                           ~23     ~22, '%0A'
         54        ECHO                                                     ~23
   55    55        INIT_FCALL                                               'getcryptedpassword'
         56        SEND_VAR                                                 !0
         57        SEND_VAR                                                 !1
         58        SEND_VAL                                                 'crypt-blowfish'
         59        DO_FCALL                                      0  $24     
         60        ECHO                                                     $24
         61      > 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/40vi4
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
         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
         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:
155.72 ms | 1415 KiB | 29 Q