Hi,

I should have mentioned I tried that. As far as I can tell, the value
is encrypted before it can be seen by any of the hooks. I did however,
solve it in a slightly different way, as below. Since the
password_confirmation field is not encrypted, I just checked that.
Still, probably if the validation can't be run, they should not be
accepted as part of the property? Don't know though, I guess you could
consider them as being run.

  property :password,     BCryptHash
  attr_accessor :password_confirmation
  validates_confirmation_of :password

  validates_with_block :password_confirmation do
    if self.password_confirmation.length < 5 or
self.password_confirmation.length > 9
      [false, "Password must be longer than 5 characters and less than
10"]
    else
      true
    end
  end



On Aug 19, 9:42 am, TheDude <[email protected]> wrote:
> BCryptHashes have to be 60 chars in length....
>
> I think what you might be looking for is ..
>
> before :valid?, :check_password_length
>
> def check_password_length
>   [false, "Password is to long!"] if @password.length > 6
> end
>
> let me know if that works :)
>
> On Aug 18, 10:29 am, joe <[email protected]> wrote:
>
> > If I have a  BCryptHash property, e.g.,
> >     property :password,     BCryptHash, :length => 6..8
> > then it appears that the length validation is run after the password
> > is converted to a hash and always fails. Is there a mechanism for
> > doing this?
>
> > Thanks.
>
> > Joe
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" 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/datamapper?hl=en.

Reply via email to