Customcert verification code - limit characters

Customcert verification code - limit characters

by Simon Harvey -
Number of replies: 1

Hello,

Thanks for customcert it is really great smile

We get a few emails each week from users who are trying to verify their certificate but aren't typing the correct code because they can't tell the difference between an "I" (uppercase i) and an "l" lowercase "L".

Is there a way to limit the characters used within the verification code?  If you can point me to the relevant PHP file I can edit it myself to prevent either of these characters from being used.

Thanks a lot.

Average of ratings: -
In reply to Simon Harvey

Re: Customcert verification code - limit characters

by Simon Harvey -
I've answered my own question.

I've copied the function random_string () in /lib/moodlelib.php so that it doesn't use the characters

function random_string_cert($length=15) {
    $randombytes = random_bytes_emulate($length);
    $pool  = 'ABCDEFGHJKLMNPQRSTVWXYZ';
    $pool .= 'abcdefghijkmnpqrstvwxyz';
    $pool .= '123456789';
    $poollen = strlen($pool);
    $string = '';
    for ($i = 0; $i < $length; $i++) {
        $rand = ord($randombytes[$i]);
        $string .= substr($pool, ($rand%($poollen)), 1);
    }
    return $string;
}


and then called this new function in /mod/customcert/classes/certificate.php