use a static rather than a constant for code chars

darcs-hash:20080622163458-34904-1be378ff9765dcfdf491ea8d38ef6c157ebe99ce.gz
This commit is contained in:
Evan Prodromou 2008-06-22 12:34:58 -04:00
parent 8a170ed8fd
commit 8a28d54f6a

View File

@ -930,15 +930,15 @@ function common_notice_uri(&$notice) {
# 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits # 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits
define('CODECHARS', '23456789ABCDEFGHJKLMNPQRSTUVWXYZ');
function common_confirmation_code($bits) { function common_confirmation_code($bits) {
# 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits
static $codechars = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
$chars = ceil($bits/5); $chars = ceil($bits/5);
$code = ''; $code = '';
for ($i = 0; $i < $chars; $i++) { for ($i = 0; $i < $chars; $i++) {
# XXX: convert to string and back # XXX: convert to string and back
$num = hexdec(common_good_rand(1)); $num = hexdec(common_good_rand(1));
$code .= CODECHARS[$num%32]; $code .= $codechars[$num%32];
} }
return $code; return $code;
} }