title: save password input as sha1() into db with symfony
body: <p>I'm wracking my brain on the most simple of things.</p>
  
  <p>I have a symfony-generated form with some customisation. I have the form saving just fine, except that the 'password' field writes the password (as expected) in normal format.</p>
  
  <p>How can I intercept this value before database-entry and sha1() it before writing?</p>
  
  <p>Code is essentially:</p>
  
  <pre><code>$this-&gt;dialog = $request-&gt;getParameter('dialog');
  $this-&gt;form = new UserForm();
  
  if ($this-&gt;getRequest()-&gt;getMethod() == "POST") {
      $this-&gt;form-&gt;bind($request-&gt;getParameter('user'));
      // intercept here, I suspect
      $user = $this-&gt;form-&gt;save();
  }
  </code></pre>
  
  <p>EDIT:
  Problem solved.</p>
  
  <p>in <em>/lib/model/User.php</em></p>
  
  <blockquote>
    <p>class User extends BaseUser {</p>
  
  <pre><code>public function save(PropelPDO $con = null)
  {
  
    if ($this-&gt;getPassword() != '')
    {
      $this-&gt;setPassword(sha1($this-&gt;getPassword()));
    }
  
    return parent::save($con);
  }
  </code></pre>
    
    <p>}</p>
  </blockquote>
  
  <p>It's fairly obvious, but not for a noob like myself. hopefully this helps someone else. If there's a better way to do this without having to extend the save() function, let me know?</p>
  
  <p>Resource: <a href="http://www.symfony-project.org/jobeet/1_4/Propel/en/10" rel="nofollow">http://www.symfony-project.org/jobeet/1_4/Propel/en/10</a> (See: <em>Protecting the Job Form with a Token</em>)</p>
  
  <p>EDIT #2: Better way to do this (as per Grad's suggestion below)</p>
  
  <p>In User model</p>
  
  <pre><code>public function setPassword($rawPassword) 
  { 
      $salt = "fgv932g2e9dshdfkdjgf927gf8hlz082";
      $password = sha1($salt . $rawPassword); 
      parent::setPassword($password);
  }
  </code></pre>