Skip to content

Instantly share code, notes, and snippets.

@jaredhoyt
Created February 11, 2011 17:45
Show Gist options
  • Save jaredhoyt/822728 to your computer and use it in GitHub Desktop.
Save jaredhoyt/822728 to your computer and use it in GitHub Desktop.
Example password validation
<?php
class User extends AppModel {
var $validate = array(
'first_name' => array('rule' => 'notEmpty', 'message' => 'Please enter a first name.'),
'last_name' => array('rule' => 'notEmpty', 'message' => 'Please enter a last name.'),
'phone' => array('rule' => array('phone', null, 'us'), 'allowEmpty' => true, 'message' => 'Please enter a valid phone number.'),
'email' => array(
'email' => array('rule' => array('email', true), 'message' => 'Please use a valid email address.'),
'isUnique' => array('rule' => 'isUnique', 'message' => 'This email address is already being used.')
),
'password_confirm' => array(
'characters' => array('rule' => 'alphaNumeric', 'message' => 'Please enter a valid password.', 'last' => true),
'confirm' => array('rule' => 'confirmPassword', 'message' => 'These passwords do not match.')
)
);
function confirmPassword() {
# Verify password and confirm match
return $this->data['User']['password'] == Security::hash($this->data['User']['password_confirm'], null, true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment