/** * Given a user's chosen nickname, generate their unixusername. * This is done by: * - lowercasing their nickname * - stripping non-alphanumeric * - verifying uniqueness in passwd file & user table * - if not unique, append a number :/ * (not the greatest, but it can be changed later) * */ public function generateUnixUsername($nickname) { // lowercase $unixname = strtolower($nickname); // find alphanumeric-only parts to use as unixname $disallowed_characters = "/[^a-z0-9]/"; $unixname = preg_replace($disallowed_characters, "", $unixname); // make sure first character is alpha character (can't start w/ a #) if (preg_match("/^[a-z]/", $unixname) == 0) { // lets not be fancy.. just prepend an "a" to their name. $unixname = "a" . $unixname; } // append numbers to the end of the name if it's not unique // to both the password file AND the user table // Test SanboxUtil last since that could be a remote call $attempted_unixname = $unixname; $x = 0; while (User::unixusernameExists($attempted_unixname) || SandBoxUtil::inPasswdFile($attempted_unixname)) { $x++; $attempted_unixname = $unixname . $x; } $unixname = $attempted_unixname; return $unixname; }