03.03 php saved
ullumski
Tags add more
auth component hash  
Note
This is my usermodel - i am trying to find out how to hash password AFTER validation (because, if validation fails - i dont want the hash sent back to the form). My (not working) approach ist commente out.
  1. <?php
  2. class User extends AppModel {
  3.  
  4.     var $name = 'User';
  5.     var $validate = array(
  6.         'benutzername' => array(
  7.             'myuser'=>array(
  8.                 'rule' => array('custom', '/^[A-Za-z0-9_@\.]*$/'),
  9.                 'required' => true,
  10.                 'message' => 'Nur Buchstaben und Zahlen erlaubt'
  11.             ),
  12.             'between' => array(
  13.                 'rule' => array('between', 4, 15),
  14.                 'message' => 'Benutzername muss zwischen 5 und 15 Zeichen haben'
  15.             ),
  16.             'unique' => array (
  17.                 'rule' => array('isUnique'),
  18.                 'message' => 'Benutzername leider schon vergeben',
  19.                 'last' => 'true'
  20.             )
  21.         ),
  22.         'passwort' => array(
  23.             'rule' => array('minLength', '6'),
  24.             'message' => 'Passwort muss mindestens 6 Zeichen haben'
  25.         ),
  26.         'passwort2' => array(
  27.             'length'=> array(
  28.                 'rule' => array('minLength', '6'),
  29.                 'message' => 'Passwort wiederholen muss mindestens 6 Zeichen haben'
  30.             ),
  31.             'valid' => array (
  32.                 'rule' => array('myMatchPasswords', 'passwort'),    // myMatchPasswords is a custom function below
  33.                 'message' => 'Passwörter stimmen nicht überein',
  34.                 'last' => 'true'
  35.             )         
  36.         ),
  37.         'email' => array(
  38.             'rule' => array('email'),
  39.             'message' => 'E-Mail ist ein Pflichtfeld'
  40.         )
  41.     );
  42.    
  43.     // THIS DOES NOT WORK AN RESULTS IN NOT SAVING THE NEW USER
  44.     // function beforeSave(){
  45.     //   $this->data[$this->name]['passwort'] = md5($this->data[$this->name]['passwort']);
  46.     //  }
  47.    
  48.     function myMatchPasswords($check, $fieldName){
  49.         return ($check['passwort2'] == $this->data[$this->name][$fieldName]);
  50.     }
  51.  
  52.     //The Associations below have been created with all possible keys, those that are not needed can be removed
  53.     var $hasMany = array(
  54.             'Note' => array('className' => 'Note',
  55.                                 'foreignKey' => 'user_id',
  56.                                 'dependent' => false,
  57.                                 'conditions' => '',
  58.                                 'fields' => '',
  59.                                 'order' => '',
  60.                                 'limit' => '',
  61.                                 'offset' => '',
  62.                                 'exclusive' => '',
  63.                                 'finderQuery' => '',
  64.                                 'counterQuery' => ''
  65.             )
  66.     );
  67.  
  68. }
  69. ?>
Parsed in 0.167 seconds, using GeSHi 1.0.7.14

Modify this Paste