special function for generating confirmation codes
darcs-hash:20080622163241-34904-199b3654328d78c0b9fe2fa85a3ecc1ab0b1262a.gz
This commit is contained in:
parent
1906237ddc
commit
8a170ed8fd
@ -140,7 +140,7 @@ class ProfilesettingsAction extends SettingsAction {
|
|||||||
|
|
||||||
$confirm = new Confirm_address();
|
$confirm = new Confirm_address();
|
||||||
|
|
||||||
$confirm->code = common_good_rand(16);
|
$confirm->code = common_confirmation_code(128);
|
||||||
$confirm->user_id = $user->id;
|
$confirm->user_id = $user->id;
|
||||||
$confirm->address = $email;
|
$confirm->address = $email;
|
||||||
$confirm->address_type = 'email';
|
$confirm->address_type = 'email';
|
||||||
|
@ -121,7 +121,7 @@ class RegisterAction extends Action {
|
|||||||
if ($email) {
|
if ($email) {
|
||||||
|
|
||||||
$confirm = new Confirm_address();
|
$confirm = new Confirm_address();
|
||||||
$confirm->code = common_good_rand(16);
|
$confirm->code = common_confirmation_code(128);
|
||||||
$confirm->user_id = $user->id;
|
$confirm->user_id = $user->id;
|
||||||
$confirm->address = $email;
|
$confirm->address = $email;
|
||||||
$confirm->address_type = 'email';
|
$confirm->address_type = 'email';
|
||||||
|
15
lib/util.php
15
lib/util.php
@ -927,3 +927,18 @@ function common_notice_uri(&$notice) {
|
|||||||
return common_local_url('shownotice',
|
return common_local_url('shownotice',
|
||||||
array('notice' => $notice->id));
|
array('notice' => $notice->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits
|
||||||
|
|
||||||
|
define('CODECHARS', '23456789ABCDEFGHJKLMNPQRSTUVWXYZ');
|
||||||
|
|
||||||
|
function common_confirmation_code($bits) {
|
||||||
|
$chars = ceil($bits/5);
|
||||||
|
$code = '';
|
||||||
|
for ($i = 0; $i < $chars; $i++) {
|
||||||
|
# XXX: convert to string and back
|
||||||
|
$num = hexdec(common_good_rand(1));
|
||||||
|
$code .= CODECHARS[$num%32];
|
||||||
|
}
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user