- /* Compute the hash for this user and extract the hash directories. */
- $hash = base_convert(crc32($username), 10, 16);
- $hash_dirs = array();
+
+ global $hash_dirs_use_md5, $hash_dirs_strip_domain;
+ static $hash_dirs = array();
+
+
+ // strip domain from username
+ if ($hash_dirs_strip_domain)
+ $user = substr($username, 0, strpos($username, '@'));
+ else
+ $user = $username;
+
+
+ // have we already calculated it?
+ if (!empty($hash_dirs[$user]))
+ return $hash_dirs[$user];
+
+
+ if ($hash_dirs_use_md5) {
+
+ $hash = md5($user);
+ //$hash = md5bin($user);
+
+ } else {
+
+ /* Compute the hash for this user and extract the hash directories. */
+ /* Note that the crc32() function result will be different on 32 and */
+ /* 64 bit systems, thus the hack below. */
+ $crc = crc32($user);
+ if ($crc & 0x80000000) {
+ $crc ^= 0xffffffff;
+ $crc += 1;
+ }
+ $hash = base_convert($crc, 10, 16);
+ }
+
+
+ $my_hash_dirs = array();