-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User profile update feature with URL encryption and User authorization.
- Loading branch information
1 parent
f1c3fba
commit 6b2f287
Showing
15 changed files
with
476 additions
and
38 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from cryptography.fernet import Fernet | ||
import base64 | ||
import logging | ||
import traceback | ||
from django.conf import settings | ||
|
||
#this is your "password/ENCRYPT_KEY". keep it in settings.py file | ||
key = Fernet.generate_key() | ||
|
||
def encrypt(txt): | ||
try: | ||
# convert integer etc to string first | ||
txt = str(txt) | ||
# get the key from settings | ||
cipher_suite = Fernet(settings.ENCRYPT_KEY) # key should be byte | ||
# #input should be byte, so convert the text to byte | ||
encrypted_text = cipher_suite.encrypt(txt.encode('ascii')) | ||
# encode to urlsafe base64 format | ||
encrypted_text = base64.urlsafe_b64encode(encrypted_text).decode("ascii") | ||
return encrypted_text | ||
except Exception as e: | ||
# log the error if any | ||
print(e) | ||
logging.getLogger("error_logger").error(traceback.format_exc()) | ||
return None | ||
|
||
|
||
def decrypt(txt): | ||
try: | ||
# base64 decode | ||
txt = base64.urlsafe_b64decode(txt) | ||
cipher_suite = Fernet(settings.ENCRYPT_KEY) | ||
decoded_text = cipher_suite.decrypt(txt).decode("ascii") | ||
return decoded_text | ||
except Exception as e: | ||
# log the error | ||
logging.getLogger("error_logger").error(traceback.format_exc()) | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
asgiref==3.5.2 | ||
cffi==1.15.1 | ||
cryptography==39.0.0 | ||
Django==4.0.4 | ||
django-crispy-forms==1.14.0 | ||
django-jazzmin==2.5.0 | ||
sqlparse==0.4.2 | ||
tzdata==2022.1 | ||
asgiref==3.5.2 | ||
Django==4.0.4 | ||
django-crispy-forms==1.14.0 | ||
django-jazzmin==2.5.0 | ||
pycparser==2.21 | ||
sqlparse==0.4.2 | ||
tzdata==2022.1 |
Oops, something went wrong.