Validation of encrypted data

给你一囗甜甜゛ 提交于 2019-12-25 03:55:37

问题


I encrypt all private data of users before storing in database with help of gem 'attr_encrypted'. For example, I have 'email_addresses' table, which contains 'encrypted_email' column. This gem decrypt data when I call object.email or when I search by emails. But I have issues with validation of this column.

I have following validations for this and other tables:

validates_length_of :email, :within => 3..100
validates_numericality_of :post_code

I should decrypt data before validation somehow, but I don't know how to do this with help of built-in Rails tools. I don't want invent custom validations for this. Please, advise.


回答1:


validations that doesn't need a db query run on the rails side so you can pass a method instead of a column to the validation methods

validates :decrypted_email, length: { within: 3..100 }

def decrypted_email
  # decrypt email here
end


来源:https://stackoverflow.com/questions/25178789/validation-of-encrypted-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!