Update migrate_passwords_passlib.py

"code is poetry"
This commit is contained in:
Rushabh Mehta 2018-04-16 14:59:10 +05:30 committed by GitHub
parent cf6fcce961
commit 52aed5e592
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,17 +4,15 @@ from frappe.utils.password import LegacyPassword
def execute():
all_auths = frappe.db.sql("""SELECT `name`, `password`, `salt` FROM `__Auth`
WHERE doctype='User' AND `fieldname`='password'""",
as_dict=True
)
WHERE doctype='User' AND `fieldname`='password'""",
as_dict=True)
for auth in all_auths:
if auth.salt and auth.salt != "":
pwd = LegacyPassword.hash(auth.password, salt=auth.salt.encode('UTF-8'))
frappe.db.sql("""UPDATE `__Auth` SET `password`=%(pwd)s, `salt`=NULL
WHERE `doctype`='User' AND `fieldname`='password' AND `name`=%(user)s""",
{'pwd': pwd, 'user': auth.name}
)
WHERE `doctype`='User' AND `fieldname`='password' AND `name`=%(user)s""",
{'pwd': pwd, 'user': auth.name})
frappe.reload_doctype("User")