3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* note: the password_hash and password_verify functions are just easy-to-use wrappers around existing crypt() functionality with secure defaults. However, while _verify will read all supported crypt algos, _hash will only produce hashes for specific algos. This is intended to increase security, but unfortunately limits compatibility with dovecot. These two functions will allow you to create and verify compatible hashes. If your version of PHP is missing password_* or random_* functions there are forward-compatibility packages available from the people who contributed those functions to PHP: https://github.com/ircmaxell/password_compat https://github.com/paragonie/random_compat */ function dovecot_sha512_crypt($plain, $rounds=8000) { $salt = random_bytes(16); $prefix = sprintf('$6$rounds=%d$%s$', $rounds, base64_encode($salt)); return '{SHA512-CRYPT}' . crypt($plain, $prefix); } function dovecot_verify($plain, $hash) { $stripped = preg_replace('/^[^\$]*/', '', $hash); return password_verify($plain, $stripped); } $dovecot_pw = '{SHA512-CRYPT}$6$rounds=8000$kOIAPAIzsgLJSTTP$7LIscGpSgWgKfR6l1ZrArkGa.p7MUgl1WT9t/K/lgPhsnggXdCuQ7cEJ.qLoXKEn61DlZrjSu4ryEGUbg50rc/'; //created with dovecot-pw var_dump( dovecot_verify('foobar', $dovecot_pw), dovecot_sha512_crypt('foobar') );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZOnsg
function name:  (null)
number of ops:  13
compiled vars:  !0 = $dovecot_pw
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ASSIGN                                                   !0, '%7BSHA512-CRYPT%7D%246%24rounds%3D8000%24kOIAPAIzsgLJSTTP%247LIscGpSgWgKfR6l1ZrArkGa.p7MUgl1WT9t%2FK%2FlgPhsnggXdCuQ7cEJ.qLoXKEn61DlZrjSu4ryEGUbg50rc%2F'
   33     1        INIT_FCALL                                               'var_dump'
   34     2        INIT_FCALL                                               'dovecot_verify'
          3        SEND_VAL                                                 'foobar'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
   35     7        INIT_FCALL                                               'dovecot_sha512_crypt'
          8        SEND_VAL                                                 'foobar'
          9        DO_FCALL                                      0  $3      
         10        SEND_VAR                                                 $3
         11        DO_ICALL                                                 
   36    12      > RETURN                                                   1

Function dovecot_sha512_crypt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZOnsg
function name:  dovecot_sha512_crypt
number of ops:  22
compiled vars:  !0 = $plain, !1 = $rounds, !2 = $salt, !3 = $prefix
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      8000
   21     2        INIT_FCALL                                               'random_bytes'
          3        SEND_VAL                                                 16
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !2, $4
   22     6        INIT_FCALL                                               'sprintf'
          7        SEND_VAL                                                 '%246%24rounds%3D%25d%24%25s%24'
          8        SEND_VAR                                                 !1
          9        INIT_FCALL                                               'base64_encode'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $6      
         12        SEND_VAR                                                 $6
         13        DO_ICALL                                         $7      
         14        ASSIGN                                                   !3, $7
   23    15        INIT_FCALL                                               'crypt'
         16        SEND_VAR                                                 !0
         17        SEND_VAR                                                 !3
         18        DO_ICALL                                         $9      
         19        CONCAT                                           ~10     '%7BSHA512-CRYPT%7D', $9
         20      > RETURN                                                   ~10
   24    21*     > RETURN                                                   null

End of function dovecot_sha512_crypt

Function dovecot_verify:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZOnsg
function name:  dovecot_verify
number of ops:  14
compiled vars:  !0 = $plain, !1 = $hash, !2 = $stripped
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   27     2        INIT_FCALL                                               'preg_replace'
          3        SEND_VAL                                                 '%2F%5E%5B%5E%5C%24%5D%2A%2F'
          4        SEND_VAL                                                 ''
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $3      
          7        ASSIGN                                                   !2, $3
   28     8        INIT_FCALL                                               'password_verify'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $5      
         12      > RETURN                                                   $5
   29    13*     > RETURN                                                   null

End of function dovecot_verify

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.23 ms | 1407 KiB | 29 Q