hi teknoid,
Thanks..I liked the idea of behavior..below is a attached behavior...
but still I need someone's help to complete the isHashed Method
<?php
App::import('Core', 'Security');
class CustomValidationBehavior extends ModelBehavior
{
function setup(&$model, $config = array())
{
}
/****
* Checks if a string is already hashed
* <b>Parameters</b>
* Model $model - reference to parent model
* Array $value - array
* Mixed $salt - either Salt String or boolean
* <b>Returns:</b>
* boolean - true if string is hashed
* - false if string is not hased
*/
function isHashed(&$model, $value = array(), $salt = false)
{
$string = array_shift($value);
//Check if salt value has to be used
if ($salt)
{
if (is_string($salt)) {
$string = $salt . $data[$this->name]['passwd'];
} else {
$string = Configure::read('Security.salt') . $string;
}
}
//Get Instance of Security
$security =& Security::getInstance();
//Check if string is md5 hashed
if($security->hashType == 'md5' && preg_match("/[A-Fa-f0-9]{32}/
i", $string)) return true;
//Check if String sha1 hashed
if($security->hashType == 'sha1' /* condition for sha1 */)
return false;
return false;
}
}
?>
On Nov 20, 1:49 pm, teknoid <[EMAIL PROTECTED]> wrote:
> 1. app model is fine... or make it a behavior.
>
> 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
-~----------~----~----~----~------~----~------~--~---