@@ 451-511 (lines=61) @@ | ||
448 | return $button; |
|
449 | } |
|
450 | ||
451 | function createRandomValue($length, $type = 'mixed') { |
|
452 | if ( ($type != 'mixed') && ($type != 'chars') && ($type != 'digits')) $type = 'mixed'; |
|
453 | ||
454 | $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
455 | $digits = '0123456789'; |
|
456 | ||
457 | $base = ''; |
|
458 | ||
459 | if ( ($type == 'mixed') || ($type == 'chars') ) { |
|
460 | $base .= $chars; |
|
461 | } |
|
462 | ||
463 | if ( ($type == 'mixed') || ($type == 'digits') ) { |
|
464 | $base .= $digits; |
|
465 | } |
|
466 | ||
467 | $value = ''; |
|
468 | ||
469 | if ( !class_exists('PasswordHash') && file_exists(DIR_FS_CATALOG . 'includes/classes/passwordhash.php') ) { |
|
470 | include(DIR_FS_CATALOG . 'includes/classes/passwordhash.php'); |
|
471 | ||
472 | $hasher = new PasswordHash(10, true); |
|
473 | ||
474 | do { |
|
475 | $random = base64_encode($hasher->get_random_bytes($length)); |
|
476 | ||
477 | for ($i = 0, $n = strlen($random); $i < $n; $i++) { |
|
478 | $char = substr($random, $i, 1); |
|
479 | ||
480 | if ( strpos($base, $char) !== false ) { |
|
481 | $value .= $char; |
|
482 | } |
|
483 | } |
|
484 | } while ( strlen($value) < $length ); |
|
485 | ||
486 | if ( strlen($value) > $length ) { |
|
487 | $value = substr($value, 0, $length); |
|
488 | } |
|
489 | ||
490 | return $value; |
|
491 | } |
|
492 | ||
493 | // fallback for v2.3.1 |
|
494 | while ( strlen($value) < $length ) { |
|
495 | if ($type == 'digits') { |
|
496 | $char = tep_rand(0,9); |
|
497 | } else { |
|
498 | $char = chr(tep_rand(0,255)); |
|
499 | } |
|
500 | ||
501 | if ( $type == 'mixed' ) { |
|
502 | if (preg_match('/^[a-z0-9]$/i', $char)) $value .= $char; |
|
503 | } elseif ($type == 'chars') { |
|
504 | if (preg_match('/^[a-z]$/i', $char)) $value .= $char; |
|
505 | } elseif ($type == 'digits') { |
|
506 | if (preg_match('/^[0-9]$/i', $char)) $value .= $char; |
|
507 | } |
|
508 | } |
|
509 | ||
510 | return $value; |
|
511 | } |
|
512 | ||
513 | function saveParameter($key, $value, $title = null, $description = null, $set_func = null) { |
|
514 | if ( !defined($key) ) { |
@@ 526-586 (lines=61) @@ | ||
523 | return $button; |
|
524 | } |
|
525 | ||
526 | function createRandomValue($length, $type = 'mixed') { |
|
527 | if ( ($type != 'mixed') && ($type != 'chars') && ($type != 'digits')) $type = 'mixed'; |
|
528 | ||
529 | $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
530 | $digits = '0123456789'; |
|
531 | ||
532 | $base = ''; |
|
533 | ||
534 | if ( ($type == 'mixed') || ($type == 'chars') ) { |
|
535 | $base .= $chars; |
|
536 | } |
|
537 | ||
538 | if ( ($type == 'mixed') || ($type == 'digits') ) { |
|
539 | $base .= $digits; |
|
540 | } |
|
541 | ||
542 | $value = ''; |
|
543 | ||
544 | if ( !class_exists('PasswordHash') && file_exists(DIR_FS_CATALOG . 'includes/classes/passwordhash.php') ) { |
|
545 | include(DIR_FS_CATALOG . 'includes/classes/passwordhash.php'); |
|
546 | ||
547 | $hasher = new PasswordHash(10, true); |
|
548 | ||
549 | do { |
|
550 | $random = base64_encode($hasher->get_random_bytes($length)); |
|
551 | ||
552 | for ($i = 0, $n = strlen($random); $i < $n; $i++) { |
|
553 | $char = substr($random, $i, 1); |
|
554 | ||
555 | if ( strpos($base, $char) !== false ) { |
|
556 | $value .= $char; |
|
557 | } |
|
558 | } |
|
559 | } while ( strlen($value) < $length ); |
|
560 | ||
561 | if ( strlen($value) > $length ) { |
|
562 | $value = substr($value, 0, $length); |
|
563 | } |
|
564 | ||
565 | return $value; |
|
566 | } |
|
567 | ||
568 | // fallback for v2.3.1 |
|
569 | while ( strlen($value) < $length ) { |
|
570 | if ($type == 'digits') { |
|
571 | $char = tep_rand(0,9); |
|
572 | } else { |
|
573 | $char = chr(tep_rand(0,255)); |
|
574 | } |
|
575 | ||
576 | if ( $type == 'mixed' ) { |
|
577 | if (preg_match('/^[a-z0-9]$/i', $char)) $value .= $char; |
|
578 | } elseif ($type == 'chars') { |
|
579 | if (preg_match('/^[a-z]$/i', $char)) $value .= $char; |
|
580 | } elseif ($type == 'digits') { |
|
581 | if (preg_match('/^[0-9]$/i', $char)) $value .= $char; |
|
582 | } |
|
583 | } |
|
584 | ||
585 | return $value; |
|
586 | } |
|
587 | ||
588 | function saveParameter($key, $value, $title = null, $description = null, $set_func = null) { |
|
589 | if ( !defined($key) ) { |