Not signed in (Sign In)
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentAuthoralake
    • CommentTimeFeb 6th 2008
     

    Where should I put statements that modify data, some of which is validated input, before it is saved to table?

    Specifically, where should I put a $this->User->password = crypt('$this->User->password','hg'); statement? Is this statement correct?

    • CommentAuthorThijs
    • CommentTimeFeb 6th 2008
     

    It's best to use one of the standard callbacks to intercept a save (or create, or update) and change something to an attribute.

    My code for a login system in which an password entered by a new user is encrypted before being saved to the database: in the model:

    function beforeCreate()
    {
      $this->encryptPassword();
      return true;
    }
    
    function encryptPassword()
    {
       $this->set('password_encrypted', sha1($this->get('password')));
    }
    

    But in this example the encrypted password is kept in another attribute (password_encrypted) than the original (password)

    More info on the Active Record callbacks in the API docs

Add your comments
    Username Password
  • Format comments as