Can I create more session objects in Flask?

Basically I want to save some user data that I do not intend to read to users.

This data should be stored for a week or so, but I can’t use the object sessionbecause I don’t want to install session.permanent = True(I already use it to control the inputs).

So basically I need a signed cookie, like a session. Is there any way to create another instance of the session object, or is there an easy way to make cookies signed?

+4
source share
1 answer

The content of the cookie is up to you, it is more or less a repository of key values ​​in the browsers of your users with an expiration date.

As for the content, for your use case you can use any symmetric encryption, for example Fernet (available in the package cryptography, cf https://cryptography.io/en/latest/ ).

As far as I know itsdangerous(from the author of the flags, cf http://pythonhosted.org/itsdangerous/ ) allows you to sign the contents of the cookie, but it does not "encrypt" it (the user can still see the contents, but not change it). itsdangerous- Dependence on btw flash drives.

+3
source

Source: https://habr.com/ru/post/1612065/


All Articles