/**
  * Try to login a user using a username and a cleartext password.
  *
  * @param string $username The username.
  * @param string $password The password in cleartext.
  * @return number The user ID of the user or -1 on failure.
  */
 public static function login($username, $password)
 {
     if (!isset($username) || !isset($password)) {
         return -1;
     }
     $ssh = new Net_SSH2(CLUSTER_HOST);
     if ($ssh->login($username, $password)) {
         // the user credentials are valid!
         // make sure this user is also allowed to access chris by checking the user table and grabbing the user id
         $userMapper = new Mapper('User');
         $userMapper->filter('username=(?)', $username);
         $userResults = $userMapper->get();
         // if user exist, return its id
         if (isset($userResults['User'][0])) {
             // setup directory if needed
             UserC::setupDir($username, $ssh);
             // valid user
             return $userResults['User'][0]->id;
         } else {
             $uid = $ssh->exec('id -u ' . $username);
             $report = "=========================================" . PHP_EOL;
             $report .= date('Y-m-d h:i:s') . ' ---> New user logging in...' . PHP_EOL;
             $report .= $username . PHP_EOL;
             $report .= $uid . PHP_EOL;
             // log logging information
             $logFile = joinPaths(CHRIS_LOG, 'new_user.log');
             $fh = fopen($logFile, 'a') or die("can't open file");
             fwrite($fh, $report);
             fclose($fh);
             // returns 0 since the user table doesnt have auto increment
             UserC::create($uid, $username);
             // setup directory if needed
             UserC::setupDir($username, $ssh);
             return $uid;
         }
     }
     // invalid credentials
     return -1;
 }