帐户激活的最佳方式

I'm trying to create an account register page with CakePHP 2.0 where user needs to activate it's new account by clicking on a link in the email he's received after insert username, email and password.

My question is how can I set an activation code inside the user record.

I thought to create a table field named activation_code and then to store an hashed version of the username to be sure the user can activate itself by clicking the email link with the activation key.

All the procedure is done but I don't know how can I set the activation_code inside the $data['User'] object and It's not clear for me if this is a good usage of the MVC framework or I should make it in a different way.

During the user registration action I've done this but I get an error when I try to create 'activation_code' dynamically:

// from the UserController class
public function register () {
    if (!empty($this->data)) {
        if ($this->data['User']['password'] == $this->data['User']['confirm_password']) {
            // here is where I get the error
            $this->data['User']['activation_key'] = AuthComponent::password($this->data['User']['email']);
            $this->User->create();
            if ($this->User->save($this->data)) {
                // private method
                $this->registrationEmail ($this->data['User']['email'], $this->data['User']['username']);
                $this->redirect(array('controller'=>'users', 'action'=>'registration', 'success'));
            }
        }
    }
}

Obviously the activation_key is an empty field inside my database.

So how can I create a filed dynamically from the controller?

I've solved the problem with the method Model::set(), so:

public function register () {
    if (!empty($this->data)) {
        if ($this->data['User']['password'] == $this->data['User']['confirm_password']) {
            $this->User->create();
            // I've used set method
            $this->User->set('activation_key', AuthComponent::password($this->data['User']['email']));
            if ($this->User->save($this->data)) {
                $this->registrationEmail ($this->data['User']['email'], $this->data['User']['username']);
                $this->redirect(array('controller'=>'users', 'action'=>'registration', 'success'));
            }
        }
    }
}
$this->data['User']['activation_key']

should be:

$this->request->data['User']['activation_key']

(You should change all references to $this->data to the new cakephp2.0 $this->request->data)