Skip to content

Instantly share code, notes, and snippets.

@tomkrush
Created June 10, 2011 03:54
Show Gist options
  • Save tomkrush/1018199 to your computer and use it in GitHub Desktop.
Save tomkrush/1018199 to your computer and use it in GitHub Desktop.
User Model and authentication using Jot
<?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