Skip to content

Instantly share code, notes, and snippets.

@jmm
Created February 13, 2012 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmm/1817056 to your computer and use it in GitHub Desktop.
Save jmm/1817056 to your computer and use it in GitHub Desktop.
Experimenting with password length validation within Kohana 3.2 ORM validation system
<?php
class Model_User extends Model_Auth_User {
protected $_raw_data;
public function rules() {
$rules = parent::rules();
$rules[ 'username' ][] = array( 'regex', array( ':value', "/^[a-zA-Z][a-zA-Z0-9-]+$/D" ) );
$rules[ 'username' ][] = array( 'max_length', array( ':value', 24 ) );
if ( $this->changed( 'password' ) ) {
$rules[ 'password' ][] = array( 'min_length', array( $this->_raw_data[ 'password' ], 8 ) );
}
// if
return $rules;
}
// rules
protected function run_filter( $field, $value ) {
$this->_raw_data[ $field ] = $value;
return parent::run_filter( $field, $value );
}
// run_filter
}
// Model_User
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment