Rev 70 | Rev 72 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 70 | Rev 71 | ||
---|---|---|---|
Line 313... | Line 313... | ||
313 | if (!isset($mcf['params']['m'])) throw new Exception('Param "m" (mode) missing'); |
313 | if (!isset($mcf['params']['m'])) throw new Exception('Param "m" (mode) missing'); |
314 | $options['mode'] = $mcf['params']['m']; |
314 | $options['mode'] = $mcf['params']['m']; |
315 | 315 | ||
316 | if ($options['mode'] == PASSWORD_VTS_MCF1_MODE_PBKDF2) { |
316 | if ($options['mode'] == PASSWORD_VTS_MCF1_MODE_PBKDF2) { |
317 | if (!isset($mcf['params']['i'])) throw new Exception('Param "i" (iterations) missing'); |
317 | if (!isset($mcf['params']['i'])) throw new Exception('Param "i" (iterations) missing'); |
318 | $options['iterations'] = $mcf['params']['i']; |
318 | $options['iterations'] = (int)$mcf['params']['i']; |
319 | } |
319 | } |
320 | 320 | ||
321 | return array( |
321 | return array( |
322 | "algo" => PASSWORD_VTS_MCF1, |
322 | "algo" => PASSWORD_VTS_MCF1, |
323 | "algoName" => "vts-mcf-v1", |
323 | "algoName" => "vts-mcf-v1", |
Line 336... | Line 336... | ||
336 | // PASSWORD_EXT_DES |
336 | // PASSWORD_EXT_DES |
337 | return array( |
337 | return array( |
338 | "algo" => PASSWORD_EXT_DES, |
338 | "algo" => PASSWORD_EXT_DES, |
339 | "algoName" => "ext-des", |
339 | "algoName" => "ext-des", |
340 | "options" => array( |
340 | "options" => array( |
341 | "iterations" => base64_int_decode(substr($hash,1,4)) |
341 | "iterations" => (int)base64_int_decode(substr($hash,1,4)) |
342 | ) |
342 | ) |
343 | ); |
343 | ); |
344 | } else if (str_starts_with($hash, '$1$')) { |
344 | } else if (str_starts_with($hash, '$1$')) { |
345 | // PASSWORD_MD5 |
345 | // PASSWORD_MD5 |
346 | return array( |
346 | return array( |
Line 355... | Line 355... | ||
355 | // PASSWORD_BLOWFISH |
355 | // PASSWORD_BLOWFISH |
356 | return array( |
356 | return array( |
357 | "algo" => PASSWORD_BLOWFISH, |
357 | "algo" => PASSWORD_BLOWFISH, |
358 | "algoName" => "blowfish", |
358 | "algoName" => "blowfish", |
359 | "options" => array( |
359 | "options" => array( |
360 | "cost" => explode('$',$hash)[2] |
360 | "cost" => (int)ltrim(explode('$',$hash)[2],'0') |
361 | ) |
361 | ) |
362 | ); |
362 | ); |
363 | } else if (str_starts_with($hash, '$5$')) { |
363 | } else if (str_starts_with($hash, '$5$')) { |
364 | // PASSWORD_SHA256 |
364 | // PASSWORD_SHA256 |
365 | return array( |
365 | return array( |
366 | "algo" => PASSWORD_SHA256, |
366 | "algo" => PASSWORD_SHA256, |
367 | "algoName" => "sha256", |
367 | "algoName" => "sha256", |
368 | "options" => array( |
368 | "options" => array( |
369 | 'rounds' => str_replace('rounds=','',explode('$',$hash)[2]) |
369 | 'rounds' => (int)str_replace('rounds=','',explode('$',$hash)[2]) |
370 | ) |
370 | ) |
371 | ); |
371 | ); |
372 | } else if (str_starts_with($hash, '$6$')) { |
372 | } else if (str_starts_with($hash, '$6$')) { |
373 | // PASSWORD_SHA512 |
373 | // PASSWORD_SHA512 |
374 | return array( |
374 | return array( |
375 | "algo" => PASSWORD_SHA512, |
375 | "algo" => PASSWORD_SHA512, |
376 | "algoName" => "sha512", |
376 | "algoName" => "sha512", |
377 | "options" => array( |
377 | "options" => array( |
378 | 'rounds' => str_replace('rounds=','',explode('$',$hash)[2]) |
378 | 'rounds' => (int)str_replace('rounds=','',explode('$',$hash)[2]) |
379 | ) |
379 | ) |
380 | ); |
380 | ); |
381 | } else { |
381 | } else { |
382 | // PASSWORD_DEFAULT |
382 | // PASSWORD_DEFAULT |
383 | // PASSWORD_BCRYPT |
383 | // PASSWORD_BCRYPT |
Line 625... | Line 625... | ||
625 | return $options; |
625 | return $options; |
626 | } |
626 | } |
627 | 627 | ||
628 | // --- Part 5: Selftest |
628 | // --- Part 5: Selftest |
629 | 629 | ||
- | 630 | /* |
|
630 | for ($i=0; $i<9999; $i++) { |
631 | for ($i=0; $i<9999; $i++) { |
631 | assert($i===base64_int_decode(base64_int_encode($i,4))); |
632 | assert($i===base64_int_decode(base64_int_encode($i,4))); |
632 | } |
633 | } |
633 | 634 | ||
634 | $rnd = random_bytes_ex(50, true, true); |
635 | $rnd = random_bytes_ex(50, true, true); |
Line 679... | Line 680... | ||
679 | 'mode' => 'pbkdf2', |
680 | 'mode' => 'pbkdf2', |
680 | 'iterations' => 0 |
681 | 'iterations' => 0 |
681 | ))); |
682 | ))); |
682 | 683 | ||
683 | echo "OK, password $password\n"; |
684 | echo "OK, password $password\n"; |
- | 685 | */ |