-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathid_handler.php
32 lines (23 loc) · 950 Bytes
/
id_handler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
function generate_bcid() {
$CHARS = str_split("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
return $CHARS[array_rand($CHARS)].$CHARS[array_rand($CHARS)].$CHARS[array_rand($CHARS)].$CHARS[array_rand($CHARS)].$CHARS[array_rand($CHARS)].$CHARS[array_rand($CHARS)].$CHARS[array_rand($CHARS)];
}
function validate_bcid($bcid) {
$stripped_bcid = str_replace([" ", "-"], "", $bcid);
$stripped_bcid = strtoupper($stripped_bcid);
if (!preg_match('/^[^A-Z^0-9]^/', $stripped_bcid) && strlen($stripped_bcid) == 7) {
return 1;
}
return 0; // fail condition
}
function format_bcid ($bcid) { // Formats to XXX-XXXX
$stripped_bcid = str_replace([' ','-'], '', $bcid);
$stripped_bcid = strtoupper($stripped_bcid);
if (!validate_bcid($stripped_bcid)) {
throw new Exception('Invalid BCID.');
}
return substr($stripped_bcid, 0, 3).'-'.substr($stripped_bcid, -4, 4);
}
$BCID = generate_bcid();
?>