tags:

views:

167

answers:

1

Hi,

I have a password inputfield where i have a md5 converter on it. The field is binded with my entity.password field (that is stored as an md5 hash).

I want to set a f:validateLength on it so a password must have a certain length. Problem is that a "" empty String has also an md5 hash. The validator doesn't check the actual input but the converted md5 hash.

Can i set the validator on the actual input, not the converted one?

<ice:inputSecret value="#{user.employer.user.password}" converter="md5hashconverter">
 <f:validateLength minimum="3" maximum="15"/>
</ice:inputSecret>

Thank you

Edit: I'm using Hibernate and my backing bean is also the "model" managed bean. I persist with EntityManager.

+1  A: 

You can't.

To me, this is also not really the right place to do the hash. It's not a "conversion" (which is supposed to be 2-way). Rather do it at the data access layer, either yourself right prior to INSERT, or just by grabbing the DB's builtin functions. Most of them provides sort of MD5() function which you can just use in your query like INSERT INTO user (name, pass) VALUES (?, MD5(?)).

Edit: as per the update, you're using Hibernate JPA. In this case you can either use JPQL to fire a "plain" save query with MD5() function inside, or to grab an EntityListener (guide here) and act on @PrePersist and maybe also @PreUpdate.

BalusC
Thank you for your answer, as always BalusC :)I edited my post so you also know how i persist. I will re-think about where i do the hash. Inside the setter would be bad design?
Michael Bavin