From ae52c7a487cb13bb9eabed55c55d973d8b6d9cc0 Mon Sep 17 00:00:00 2001 From: Makarand Bauskar Date: Thu, 18 May 2017 12:08:06 +0530 Subject: [PATCH] [minor] added error message if the encryption_key in the site_config is changed (#3326) --- frappe/utils/password.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/frappe/utils/password.py b/frappe/utils/password.py index 5f813d9e7b..40dedf8175 100644 --- a/frappe/utils/password.py +++ b/frappe/utils/password.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe from frappe import _ from frappe.utils import cstr, encode -from cryptography.fernet import Fernet +from cryptography.fernet import Fernet, InvalidToken def get_decrypted_password(doctype, name, fieldname='password', raise_exception=True): auth = frappe.db.sql('''select `password` from `__Auth` @@ -97,9 +97,13 @@ def encrypt(pwd): return cipher_text def decrypt(pwd): - cipher_suite = Fernet(encode(get_encryption_key())) - plain_text = cstr(cipher_suite.decrypt(encode(pwd))) - return plain_text + try: + cipher_suite = Fernet(encode(get_encryption_key())) + plain_text = cstr(cipher_suite.decrypt(encode(pwd))) + return plain_text + except InvalidToken: + # encryption_key in site_config is changed and not valid + frappe.throw(_('Encryption key is invalid, Please check site_config.json')) def get_encryption_key(): from frappe.installer import update_site_config