diff --git a/components/signup.php b/components/signup.php index 3e722a1e9a1eccc7bc9c2da21a0cc14171497165..c850da587ed2f37709fdedab0757fbd8480005a7 100644 --- a/components/signup.php +++ b/components/signup.php @@ -128,16 +128,8 @@ if (isset($_REQUEST['signupid']) && isset($_REQUEST['signuppw'])) { ); $failed = true; } else { - // determine the uid range - if ($row[type] == 2) { - $baseuid = 8; - } else { - $baseuid = 29; - } - $minuid = $baseuid * 1000; - $maxuid = $minuid + 999; - //get the new uid - $uid = findUid($minuid, $maxuid); + //generate the new uid + $uid = generateUid(); // make a password $password = make_password(); // make the ldif diff --git a/lib/member_functions.php b/lib/member_functions.php index a7a570191f6acf3acbf466ba12281e64ea7e2c1b..f5f4d7be93954a1775fc12f1b574ef2642dc99da 100644 --- a/lib/member_functions.php +++ b/lib/member_functions.php @@ -29,21 +29,30 @@ function make_password($length = 8) return $password; } -function findUid($start, $end) +function generateUid() { - $ds = ldap_connect("localhost"); - ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); - $r = ldap_bind($ds); - $sr = ldap_search($ds, "dc=sucs,dc=org", "uid=*", array(uidNumber)); - $info = ldap_get_entries($ds, $sr); - for ($i = 0; $i < $info[count]; $i++) { - $uids[$info[$i][uidnumber][0]] = true; - } - for ($i = $start; $i < $end; $i++) { - if (!isset($uids[$i])) { - $safeuid = $i; - break; + + //get the year, this'll be the start/prefix of the uid + $prefix = date("Y"); + + //generate a uid + //check to see if it's taken/safe to use + $ok = false; + while ($ok == false) { + + //generate random number between 00000 and 99999 + $uid = sprintf("%05d", mt_rand(0, 99999)); + + //id return 1 for error (safe to take). 0 for success (taken) not safe + exec("id ".$prefix.$uid, $output, $returnVal); + + //check the result of id + if ($returnVal == 1) { + // We have an unused one! + $ok = true; + $safeuid = $prefix.$uid; } + } return $safeuid;