Speed up development with full-stack environments for every branch.

Learn More

How to do Basic Authentication using CakePHP [sessions]

Forked from Welcome to CakePHP.

5010 Runs 19742 Views 24617 Copies
Saved

Saved

jacekjp 4

jacekjp
published 4 years ago

<?php
class User extends AppModel {
    /* validate data enetered by user */
    public $validate = array(
        'username' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'A username is required'
            )
        ),
        'password' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'A password is required'
            )
        )
    );
    
    public function beforeSave($options = array()) {
        
    /* password hashing */    
    if (isset($this->data[$this->alias]['password'])) {
        $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
    }
    return true;
}
}
 
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).