From a763320a140e3cdfc96cf602091f3374a71918ac Mon Sep 17 00:00:00 2001 From: Marco Rougeth Date: Wed, 19 Nov 2014 15:45:13 -0200 Subject: [PATCH] Remove i and l from certificate code to improve legibility --- lib.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib.php b/lib.php index fa29788..64eca8a 100644 --- a/lib.php +++ b/lib.php @@ -1513,6 +1513,18 @@ function certificate_print_image($pdf, $certificate, $type, $x, $y, $w, $h) { } } +function custom_random_string($length=15) { + $pool = 'ABCDEFGHJKMNOPQRSTUVWXYZ'; + $pool .= 'abcdefghjkmnopqrstuvwxyz'; + $pool .= '0123456789'; + $poollen = strlen($pool); + $string = ''; + for($i=0; $i < $length; $i++) { + $string .= substr($pool, (mt_rand()%($poollen)), 1); + } + return $string; +} + /** * Generates a 10-digit code of random letters and numbers. * @@ -1522,12 +1534,12 @@ function certificate_generate_code() { global $DB; $uniquecodefound = false; - $code = random_string(10); + $code = custom_random_string(10); while (!$uniquecodefound) { if (!$DB->record_exists('certificate_issues', array('code' => $code))) { $uniquecodefound = true; } else { - $code = random_string(10); + $code = custom_random_string(10); } }