Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class User extends ActiveRecord\Model {
- var $pass = FALSE;
- public function pre_save() {
- if($this->pass)
- $this->password($this->pass);
- }
- private function hash_password($pass) {
- $salt = bin2hex(mcrypt_create_iv(32,MCRYPT_DEV_URANDOM));
- $hash = hash('sha256',$salt.$pass);
- return $salt.$hash;
- }
- private function validate_password($password)
- {
- $salt = substr($this->password,1,64);
- $hash = substr($this->password,65,128);
- $password_hash = hash('sha256',$salt.$hash);
- return $hash == $password_hash;
- }
- public static function login($username, $password) {
- $user = User::find_by_username($username);
- if($user && $user->validate_password($password))
- return $user;
- else
- return FALSE;
- }
- }
- /*
- * end of file User.php
- * ./application/models/User.php
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement