jmazzi / crypt_keeper

Transparent ActiveRecord encryption
http://jmazzi.github.com/crypt_keeper/
MIT License
288 stars 99 forks source link

String length validation for encrypted filed? #186

Closed shrkw closed 4 years ago

shrkw commented 4 years ago

Hi,

I want to validate length for encrypted filed. But standard way counts as byte length. So it does not work for string length.

validates :name, length: { maximum: 20 }

Do you have any idea for that?

shrkw commented 4 years ago

Sorry, this is due to multi byte encoding. I can validate by name.force_encoding('utf-8').length.

Sorry to bother you.

jmazzi commented 4 years ago

Hello,

What is the purpose of validating the length of the field? 

On October 2, 2020, Khushhal Maheshwari notifications@github.com wrote:

Hi,

I want to validate length for encrypted filed.  But standard way counts as byte length. So it does not work for

string length.

validates :name, length: { maximum: 80 } Do you have any idea for that?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jmazzi/crypt_keeper/issues/186, or unsubscribe https://github.com/notifications/unsubscribe- auth/AAAARYPN63EMVIABKWZ4K4TSIWMP7ANCNFSM4SBPEWRA.

shrkw commented 4 years ago

I think it is common use case though, I don't want to accept too long name input to users. I added client side length validation, and I wanted to add it on rails side too.