Hi All,

I am having some issues with the following: I have 2 tables that I
have saving data to, accounts and users. I need to save the password
field within users as MD5 and so I am using beforesave function in my
model. It seems to be ignoring it though. Any ideas how I can go about
this?

ACCOUNT model
----------------------------------------------------------------
function beforeSave() {
   if ($this->data['User'][0]['password'])
   {
                $this->data['User'][0]['password'] = md5($this->data['User'][0]
['password']);
                echo $this->data['User'][0]['password'];
   }
   return true;
}
-----------------------------------------------

NOTE: Above I have echo $this->data['User'][0]['password'], this is
printing out the encrypted password...

ACCOUNT controller
------------------------------------------------------------------

        function edit($id = null) {
                if (!$id && empty($this->data)) {
                        $this->Session->setFlash(__('Invalid account', true));
                        $this->redirect(array('action' => 'index'));
                }
                if (!empty($this->data))
                {
                        if ($this->Account->save($this->data))
                        {
                                $this->data['User'][0]['account_id'] = 
$this->Account->id;
                                $this->Account->User->save($this->data);

                                $this->Session->setFlash(__('The account has 
been saved', true));
                                echo "<pre>";
                                print_r($this->data);
                                echo "</pre>";
                                //$this->redirect(array('action' => 'index'));
                        } else {
                                $this->Session->setFlash(__('The account could 
not be saved.
Please, try again.', true));
                        }
                }
                if (empty($this->data)) {
                        $this->data = $this->Account->read(null, $id);
                }
                //$users = $this->Account->User->find('list');
                //$this->set(compact('users'));
        }
----------------------------------------------------------------
NOTE: by this stage the password is back to the unencrypted way...
(when I call the print_r($this->data);)


Thanks

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to