diff options
author | Evan Prodromou <evan@controlezvous.ca> | 2008-06-22 12:32:41 -0400 |
---|---|---|
committer | Evan Prodromou <evan@controlezvous.ca> | 2008-06-22 12:32:41 -0400 |
commit | 8a170ed8fd014cb7640b04c535a359b3275681fd (patch) | |
tree | 9dcfbd67db4df4d5930d92b8d13d60002a2ba37d /lib/util.php | |
parent | 1906237ddc5c74e385dd6c722457dfc819937114 (diff) |
special function for generating confirmation codes
darcs-hash:20080622163241-34904-199b3654328d78c0b9fe2fa85a3ecc1ab0b1262a.gz
Diffstat (limited to 'lib/util.php')
-rw-r--r-- | lib/util.php | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/util.php b/lib/util.php index 49349a72f..18043e867 100644 --- a/lib/util.php +++ b/lib/util.php @@ -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; +} |