]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
special function for generating confirmation codes
authorEvan Prodromou <evan@controlezvous.ca>
Sun, 22 Jun 2008 16:32:41 +0000 (12:32 -0400)
committerEvan Prodromou <evan@controlezvous.ca>
Sun, 22 Jun 2008 16:32:41 +0000 (12:32 -0400)
darcs-hash:20080622163241-34904-199b3654328d78c0b9fe2fa85a3ecc1ab0b1262a.gz

actions/profilesettings.php
actions/register.php
lib/util.php

index c14a3f640dd0b91331f2a3072583d2faa455eb0c..95f625de9b9dcb4260cd092a2b818e4d981e65ab 100644 (file)
@@ -140,7 +140,7 @@ class ProfilesettingsAction extends SettingsAction {
 
                        $confirm = new Confirm_address();
                        
-                       $confirm->code = common_good_rand(16);
+                       $confirm->code = common_confirmation_code(128);
                        $confirm->user_id = $user->id;
                        $confirm->address = $email;
                        $confirm->address_type = 'email';
index 862ca2a784f134d02700ea155b20d495b2a5b8f6..31c8fea70fad08b6df2cef19e1a0d8492841405a 100644 (file)
@@ -121,7 +121,7 @@ class RegisterAction extends Action {
                if ($email) {
                        
                        $confirm = new Confirm_address();
-                       $confirm->code = common_good_rand(16);
+                       $confirm->code = common_confirmation_code(128);
                        $confirm->user_id = $user->id;
                        $confirm->address = $email;
                        $confirm->address_type = 'email';
index 49349a72f09873255a023ae7cdcfda7495e8009b..18043e867083cd44aab31b199461da433439136c 100644 (file)
@@ -927,3 +927,18 @@ function common_notice_uri(&$notice) {
        return common_local_url('shownotice', 
                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;
+}