Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- controller
- public function register()
- {
- $register = User::create(array(
- 'username' => 'test1',
- 'password' => 'testpass'
- ));
- $register->re_password = 'testpass';
- if($register->is_valid())
- {
- echo 'Login';
- }
- else
- {
- print_r($register->errors->full_messages());
- }
- }
- Model
- <?php
- class User extends ActiveRecord\Model
- {
- var $password = FALSE;
- var $re_password = FALSE;
- static $validates_presence_of = array(
- array('username'),
- array('password')
- );
- static $validates_size_of = array(
- array('username', 'within' => array(3,15)),
- array('password', 'minimum' => 6)
- );
- public function validate()
- {
- if($this->password != $this->re_password && $this->re_password != $this->password)
- {
- echo $this->password;
- $this->errors->add('Password', "and retype password must me be the same.");
- }
- }
- function before_save()
- {
- if($this->password)
- {
- $this->hashed_password = $this->hash_password($this->password);
- }
- }
- private function hash_password($password)
- {
- $salt = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
- $hash = hash('sha256', $salt . $password);
- return $salt . $hash;
- }'
Add Comment
Please, Sign In to add comment