[html-formfu] Constraint for salted hash password

Carl Franks fireartist at gmail.com
Fri Feb 27 12:25:09 GMT 2009


2009/2/27 Christian Lackas <christian at lackas.net>:
> * Moritz Onken <onken at houseofdesign.de> [090227 11:15]:
>
> Hi Moritz,
>
>> > My idea was to have this in my form.yml:
>> >
>> >    - type: Password
>> >      name: password_old
>> >      label: Old password
>> >      filters:
>> >        - type: Callback
>> >          callback: MyApp::Utils::hashpassword
>> >      constraint:
>> >        - type: Set
>> >          message: Password does not match
>> You can try to create a Transformer. This one is called after a constraint
>> is checked.
>
> Found the problem, after digging some more through the documentation:
>
>    [ in Controller, which known $user ]
>
>    $field->validator('Callback')->callback( sub {
>        return Crypt::SaltedHash->validate($user->password, shift);
>    });
>
> One more question, how do I set a custom message? I use
>
>    - type: Password
>      name: password_old
>      label: Old password
>      validator:
>        - type: Callback
>          message: Password does not match
>
> together with above line, but that does not really help (works for
> constraints, though). Still just says 'Validator error'.

You're adding a 2nd validator, so it doesn't have the message set on the 1st.
That should really be:

   $field->get_validator({ type => 'Callback' })->callback( sub {
       return Crypt::SaltedHash->validate($user->password, shift);
   });

Carl



More information about the HTML-FormFu mailing list