<html lang='en'>
<head>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<title>
GitLab
</title>
</meta>
</head>
<style>
img {
max-width: 100%;
height: auto;
}
p.details {
font-style:italic;
color:#777
}
.footer p {
font-size:small;
color:#777
}
pre.commit-message {
white-space: pre-wrap;
}
.file-stats a {
text-decoration: none;
}
.file-stats .new-file {
color: #090;
}
.file-stats .deleted-file {
color: #B00;
}
</style>
<body>
<div class='content'>
<h3>
Laurence Sebastian Bowes pushed to branch master
at <a href="https://projects.sucs.org/sucssite/sucs-site">sucssite / sucs-site</a>
</h3>
<h4>
Commits:
</h4>
<ul>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/a16d95d05b16377dbc5b3c30ddf254a5493eae58">a16d95d0</a></strong>
<div>
<span>by Imran Hussain</span>
<i>at 2015-12-29T17:07:38+00:00</i>
</div>
<pre class='commit-message'>Replace the old UID generation.
New UID generation system that uses the full year as a prefix. Should stop UIDs
from being reused.</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/080478fe19d550e7de5157cdb22c290025f6b306">080478fe</a></strong>
<div>
<span>by Laurence Sebastian Bowes</span>
<i>at 2016-02-13T03:26:59+00:00</i>
</div>
<pre class='commit-message'>Twat</pre>
</li>
<li>
<strong><a href="https://projects.sucs.org/sucssite/sucs-site/commit/c2f7394d9ed8408f824008a6a2ed5a57f03af51e">c2f7394d</a></strong>
<div>
<span>by Laurence Sebastian Bowes</span>
<i>at 2016-02-13T03:44:17+00:00</i>
</div>
<pre class='commit-message'>Minor fixes. Happy with this code now.</pre>
</li>
</ul>
<h4>2 changed files:</h4>
<ul>
<li class='file-stats'>
<a href='#diff-0'>
components/signup.php
</a>
</li>
<li class='file-stats'>
<a href='#diff-1'>
lib/member_functions.php
</a>
</li>
</ul>
<h4>Changes:</h4>
<li id='diff-0'>
<a href='https://projects.sucs.org/sucssite/sucs-site/compare/d788d45fc86397a139212b181fdc8861332c9e75...c2f7394d9ed8408f824008a6a2ed5a57f03af51e#diff-0'>
<strong>
components/signup.php
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/components/signup.php
</span><span style="color: #000000;background-color: #ddffdd">+++ b/components/signup.php
</span><span style="color: #aaaaaa">@@ -128,16 +128,8 @@ if (isset($_REQUEST['signupid']) && isset($_REQUEST['signuppw'])) {
</span> );
$failed = true;
} else {
<span style="color: #000000;background-color: #ffdddd">- // 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);
</span><span style="color: #000000;background-color: #ddffdd">+ //generate the new uid
+ $uid = generateUid();
</span> // make a password
$password = make_password();
// make the ldif
</code></pre>
<br>
</li>
<li id='diff-1'>
<a href='https://projects.sucs.org/sucssite/sucs-site/compare/d788d45fc86397a139212b181fdc8861332c9e75...c2f7394d9ed8408f824008a6a2ed5a57f03af51e#diff-1'>
<strong>
lib/member_functions.php
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/lib/member_functions.php
</span><span style="color: #000000;background-color: #ddffdd">+++ b/lib/member_functions.php
</span><span style="color: #aaaaaa">@@ -29,21 +29,30 @@ function make_password($length = 8)
</span> return $password;
}
<span style="color: #000000;background-color: #ffdddd">-function findUid($start, $end)
</span><span style="color: #000000;background-color: #ddffdd">+function generateUid()
</span> {
<span style="color: #000000;background-color: #ffdddd">- $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;
</span><span style="color: #000000;background-color: #ddffdd">+
+ //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;
</span> }
<span style="color: #000000;background-color: #ddffdd">+
</span> }
return $safeuid;
</code></pre>
<br>
</li>
</div>
<div class='footer' style='margin-top: 10px;'>
<p>
—
<br>
<a href="https://projects.sucs.org/sucssite/sucs-site/compare/d788d45fc86397a139212b181fdc8861332c9e75...c2f7394d9ed8408f824008a6a2ed5a57f03af51e">View it on GitLab</a>.
<br>
You're receiving this email because of your account on projects.sucs.org.
If you'd like to receive fewer emails, you can
adjust your notification settings.
</p>
</div>
</body>
</html>