randomString() public method

Generate a random string of the given length.
public randomString ( $length )
 function setToken($login)
 {
     require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "settings.class.php";
     require_once $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . "common.class.php";
     $settings = new settings();
     $common = new common();
     // Create a new token and make sure it is unique.
     $token = $common->randomString(10);
     $goodToken = FALSE;
     while (!$goodToken) {
         $goodToken = TRUE;
         if ($settings::db_driver == "xml") {
             // XML
             $administrators = simplexml_load_file($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "administrators.xml");
             foreach ($administrators->xpath("administrator[login='******']") as $administrator) {
                 if ($administrator->token == $token) {
                     $goodToken = FALSE;
                 }
             }
         } else {
             $dbh = $common->pdoOpen();
             $sql = "SELECT COUNT(*) FROM " . $settings::db_prefix . "administrators WHERE token = :token";
             $sth = $dbh->prepare($sql);
             $sth->bindParam(':token', $token, PDO::PARAM_STR, 10);
             $sth->execute();
             $count = $sth->fetchColumn();
             $sth = NULL;
             $dbh = NULL;
             if ($count > 0) {
                 $goodToken = FALSE;
             }
         }
     }
     // Assign this token to the administrator.
     if ($settings::db_driver == "xml") {
         // XML
         $administrators = simplexml_load_file($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "administrators.xml");
         foreach ($administrators->xpath("administrator[login='******']") as $administrator) {
             $administrator->token = $token;
         }
         file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "administrators.xml", $administrators->asXML());
     } else {
         // PDO
         $dbh = $common->pdoOpen();
         $sql = "UPDATE " . $settings::db_prefix . "administrators SET token = :token WHERE login = :login";
         $sth = $dbh->prepare($sql);
         $sth->bindParam(':token', $token, PDO::PARAM_STR, 10);
         $sth->bindParam(':login', $login, PDO::PARAM_STR, 25);
         $sth->execute();
         $sth = NULL;
         $dbh = NULL;
     }
     return $token;
 }