title: Unique Token Id on every login In Symfony 1.4 / Doctrine
body: <p>I am using an older version of Symfony 1.4</p>
  
  <p>And I am using the sfGuardDoctrine plugin for basic security.</p>
  
  <p>I want to double check that this will do what I want and also if there may be a better way to accomplish what I am doing. </p>
  
  <pre><code> // make sure that the key is not in the database on signin    
  do {
      // generate new keys
      $key = $this-&gt;generateRandomKey();
      // make sure random key is not used
      $key_check = Doctrine::getTable('sfGuardUserProfile')-&gt;checkDuplicateKey($key);    
  } while (count($key_check) &lt; 1);
  </code></pre>
  
  <p>generate random key code</p>
  
  <pre><code>private function generateRandomKey($len = 20)
  {
    return base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
  }
  </code></pre>
  
  <p>The Doctrine Query to get Token Id's</p>
  
  <pre><code> static public function checkDuplicateKey($key) 
  {
      return Doctrine_Query::create()
          -&gt;select('u.token_id')
          -&gt;from('sfGuardUserProfile u')
          -&gt;where('u.token_id = ?')
          -&gt;fetchOne(array($key), Doctrine::HYDRATE_ARRAY);
  }
  </code></pre>
  
  <p>This code executes whenever a user logs in.
  My questions are
  1) Will it give me a unique id for every user? and 2) Is there a better way to accomplish this task?</p>
  
  <p>Thank you in advance</p>