Giter Site home page Giter Site logo

Comments (8)

svetlyak40wt avatar svetlyak40wt commented on July 26, 2024

You are right. It is impossible to search over encrypted values. And there is no workaround.

Probably, the only way is to use some 3d party solution, like haystack, to add a search index, using unencrypted data, but this approach could lead for security issues.

from django-fields.

getnoel avatar getnoel commented on July 26, 2024

Hi,

I think this is related to the object manager. When I tried MyModel.objects.get(email=user_email) it always says "matching query does not exist"

I tried adding method "get_prep_lookup" on BaseEncryptedField like this:

def get_prep_lookup(self, lookup_type, value):
value = self.get_db_prep_value(value)
return super(BaseEncryptedField, self).get_prep_lookup(lookup_type, value)

This isn't working because the method "get_db_prep_value" is appending random value from string.printable which isn't reversible. I changed this line into something reversible and everything worked as expected.

Hope this will be fixed.

Thanks

from django-fields.

svetlyak40wt avatar svetlyak40wt commented on July 26, 2024

What did you use to replace random value?

from django-fields.

getnoel avatar getnoel commented on July 26, 2024

I changed "random.choice(string.printable)" into "string.printable[index:index + 1] or 0". This way the get_prep_lookup will be able to recreate the encrypted value. I don't know if this would weaken the security.

I'm sorry, I think this didn't solve the admin search, but it did solve the "get" method of the object manager. I don't know why the search was working and now its not.

from django-fields.

getnoel avatar getnoel commented on July 26, 2024

Aha, I was searching using exact match. So if I search using a part or phrase it cant find any match.

from django-fields.

svetlyak40wt avatar svetlyak40wt commented on July 26, 2024

That is make sense, because part of the phrase can't be same as the whole phrase, after encoding.

from django-fields.

svetlyak40wt avatar svetlyak40wt commented on July 26, 2024

Probably, the best to close this issue, if there is now complete solution.

from django-fields.

getnoel avatar getnoel commented on July 26, 2024

Yeah, this doesn't solve the MyModel.objects.filter method too :(

from django-fields.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.