问题
till now I tried more then 6 plugins and quite frustrate now. Now using this one cryprtography
everything is fine and done accordingly but when I save data in model manager like this
def create_user(self, email, password, **extra_fields):
user = self.model(email=email, **extra_fields)
user.test_field = 'new.user@oc.com'
user.save(using=self._db)
return user
it saving data normally not encrypted
My model is like
class User(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=255, unique=True)
name = models.CharField(max_length=255)
test_field = encrypt(models.CharField(max_length=100))
objects = UserManager()
回答1:
It looks like you are doing everything as expected.
Data should be encrypted on the Database end.
However, it's normal to see the data in clear text on Django side because the ORM decrypt it seamlessly.
If you check the data directly on the database (using raw SQL query without an ORM), you should see encrypted data.
If you need to filter encrypted data, you should do it in python, after ORM decryption :
Instead of doing User.objects.filter(test_field__contains="somedata")
, you will need to do [user for user in User.objects.all() if "somedata" in user.test_field]
. The (big) drawback of this method is that you will need to pass all rows into the ORM (and decryption mecanism)
来源:https://stackoverflow.com/questions/64323636/data-is-not-being-saved-as-encrypted-data-django