Maybe I am missing something, but why not just Hash as part of validation, then you'll know it is not hashed until after the compare?
http://edwardawebb.com/programming/php-programming/cakephp/complex-validation-cakephp-12 On Nov 20, 12:24 pm, bingo <[EMAIL PROTECTED]> wrote: > Hi bakers, > > I am trying to write a custom validation function that checks if a > string is already hashed or not. I want to make sure that password > filed are hashed and if not then hash them. Further, I can see it > being useful in many other cases. Pertaining to custom validation, I > have two questions > > 1. Where should I put validation function that are generic and not > particular to any model. Is app_model is the right place ? I just > don't want to put too many things in app_model and was thinking making > another file that holds custom validation functions. > > 2. Can someone help me completing this function. I got the start but > not being able to complete it > > /**** > * Checks if a string is already hashed > * <b>Parameters</b> > * String $string - input String > * mixed $salt - either string or boolean > * <b>Returns:</b> > * boolean - true if string is hashed > * - false if string is not hased > */ > function isHashed($string, $salt = false) > { > //Check if salt value has to be used - copied from Security.php > if ($salt) > { > if (is_string($salt)) { > $string = $salt . $string; > } else { > $string = Configure::read('Security.salt') . $string; > } > } > > //Check if string is already hashed > $security =& Security::getInstance(); > if($secuirty->hashType == 'md5') > if(preg_match("/[A-Fa-f0-9]{32}/i", $string)) return true; > return false; > > } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
