@@ 427-487 (lines=61) @@ | ||
424 | return $button; |
|
425 | } |
|
426 | ||
427 | function createRandomValue($length, $type = 'mixed') { |
|
428 | if ( ($type != 'mixed') && ($type != 'chars') && ($type != 'digits')) $type = 'mixed'; |
|
429 | ||
430 | $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
431 | $digits = '0123456789'; |
|
432 | ||
433 | $base = ''; |
|
434 | ||
435 | if ( ($type == 'mixed') || ($type == 'chars') ) { |
|
436 | $base .= $chars; |
|
437 | } |
|
438 | ||
439 | if ( ($type == 'mixed') || ($type == 'digits') ) { |
|
440 | $base .= $digits; |
|
441 | } |
|
442 | ||
443 | $value = ''; |
|
444 | ||
445 | if ( !class_exists('PasswordHash') && file_exists(DIR_FS_CATALOG . 'includes/classes/passwordhash.php') ) { |
|
446 | include(DIR_FS_CATALOG . 'includes/classes/passwordhash.php'); |
|
447 | ||
448 | $hasher = new PasswordHash(10, true); |
|
449 | ||
450 | do { |
|
451 | $random = base64_encode($hasher->get_random_bytes($length)); |
|
452 | ||
453 | for ($i = 0, $n = strlen($random); $i < $n; $i++) { |
|
454 | $char = substr($random, $i, 1); |
|
455 | ||
456 | if ( strpos($base, $char) !== false ) { |
|
457 | $value .= $char; |
|
458 | } |
|
459 | } |
|
460 | } while ( strlen($value) < $length ); |
|
461 | ||
462 | if ( strlen($value) > $length ) { |
|
463 | $value = substr($value, 0, $length); |
|
464 | } |
|
465 | ||
466 | return $value; |
|
467 | } |
|
468 | ||
469 | // fallback for v2.3.1 |
|
470 | while ( strlen($value) < $length ) { |
|
471 | if ($type == 'digits') { |
|
472 | $char = tep_rand(0,9); |
|
473 | } else { |
|
474 | $char = chr(tep_rand(0,255)); |
|
475 | } |
|
476 | ||
477 | if ( $type == 'mixed' ) { |
|
478 | if (preg_match('/^[a-z0-9]$/i', $char)) $value .= $char; |
|
479 | } elseif ($type == 'chars') { |
|
480 | if (preg_match('/^[a-z]$/i', $char)) $value .= $char; |
|
481 | } elseif ($type == 'digits') { |
|
482 | if (preg_match('/^[0-9]$/i', $char)) $value .= $char; |
|
483 | } |
|
484 | } |
|
485 | ||
486 | return $value; |
|
487 | } |
|
488 | ||
489 | function saveParameter($key, $value, $title = null, $description = null, $set_func = null) { |
|
490 | if ( !defined($key) ) { |
@@ 500-560 (lines=61) @@ | ||
497 | return $button; |
|
498 | } |
|
499 | ||
500 | function createRandomValue($length, $type = 'mixed') { |
|
501 | if ( ($type != 'mixed') && ($type != 'chars') && ($type != 'digits')) $type = 'mixed'; |
|
502 | ||
503 | $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
504 | $digits = '0123456789'; |
|
505 | ||
506 | $base = ''; |
|
507 | ||
508 | if ( ($type == 'mixed') || ($type == 'chars') ) { |
|
509 | $base .= $chars; |
|
510 | } |
|
511 | ||
512 | if ( ($type == 'mixed') || ($type == 'digits') ) { |
|
513 | $base .= $digits; |
|
514 | } |
|
515 | ||
516 | $value = ''; |
|
517 | ||
518 | if ( !class_exists('PasswordHash') && file_exists(DIR_FS_CATALOG . 'includes/classes/passwordhash.php') ) { |
|
519 | include(DIR_FS_CATALOG . 'includes/classes/passwordhash.php'); |
|
520 | ||
521 | $hasher = new PasswordHash(10, true); |
|
522 | ||
523 | do { |
|
524 | $random = base64_encode($hasher->get_random_bytes($length)); |
|
525 | ||
526 | for ($i = 0, $n = strlen($random); $i < $n; $i++) { |
|
527 | $char = substr($random, $i, 1); |
|
528 | ||
529 | if ( strpos($base, $char) !== false ) { |
|
530 | $value .= $char; |
|
531 | } |
|
532 | } |
|
533 | } while ( strlen($value) < $length ); |
|
534 | ||
535 | if ( strlen($value) > $length ) { |
|
536 | $value = substr($value, 0, $length); |
|
537 | } |
|
538 | ||
539 | return $value; |
|
540 | } |
|
541 | ||
542 | // fallback for v2.3.1 |
|
543 | while ( strlen($value) < $length ) { |
|
544 | if ($type == 'digits') { |
|
545 | $char = tep_rand(0,9); |
|
546 | } else { |
|
547 | $char = chr(tep_rand(0,255)); |
|
548 | } |
|
549 | ||
550 | if ( $type == 'mixed' ) { |
|
551 | if (preg_match('/^[a-z0-9]$/i', $char)) $value .= $char; |
|
552 | } elseif ($type == 'chars') { |
|
553 | if (preg_match('/^[a-z]$/i', $char)) $value .= $char; |
|
554 | } elseif ($type == 'digits') { |
|
555 | if (preg_match('/^[0-9]$/i', $char)) $value .= $char; |
|
556 | } |
|
557 | } |
|
558 | ||
559 | return $value; |
|
560 | } |
|
561 | ||
562 | function saveParameter($key, $value, $title = null, $description = null, $set_func = null) { |
|
563 | if ( !defined($key) ) { |