Created
June 10, 2011 03:54
-
-
Save tomkrush/1018199 to your computer and use it in GitHub Desktop.
User Model and authentication using Jot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class User_Model extends My_Model | |
{ | |
public function init() | |
{ | |
$this->transient('confirm_password'); | |
$this->before_save('encrypt_password'); | |
$this->validates('password', array('presence', 'confirm')); | |
} | |
protected function encrypt_password() | |
{ | |
$password = md5($this->read_attribute('password')); | |
$this->write_attribute('password', $password); | |
} | |
public function authenticate($username, $password) | |
{ | |
return $this->exists(array( | |
'username' => $username, | |
'password' => md5($password) | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment