I have a document in which has a button which opens a dialog box asking for password verification to set a check field ,
But not the password for the current user , its basically the supervisor , so he will select his user name(from drop down) and enter password , if verified --success ,–
So i connot use the frappe.verify_password
function as it verifies current users password .
i did it in the old version using a verification from db queries , below was y function .
@frappe.whitelist()
def dis_auth(user,password):
manager=frappe.db.sql("select u.name from tabUser u, `tabHas Role` ur where u.name=ur.parent and ur.role='Sales Master Manager' and u.name='%s'"%(user))
if manager:
auth = frappe.db.sql("""select name, `password`, salt from `__Auth`
where doctype='User' and fieldname='password' and encrypted=0 and name='%s'
and (
(salt is null and `password`=password('%s'))
or `password`=password(concat('%s', salt))
)"""%(user,password,password), as_dict=True)
if auth:
return "Yes"
else:
frappe.msgprint("Invalid Password.")
return "No"
frappe.msgprint("Selected User is not Sales Master Manager")
return "No"
and it worked perfectly, the but db structure has changed ,
and the query
frappe.db.sql("""select name, `password`, salt from `__Auth` where doctype='User' and fieldname='password' and encrypted=0 and name='%s' and ( (salt is null and `password`=password('%s')) or `password`=password(concat('%s', salt)) )"""%(user,password,password), as_dict=True)
does not work anymore , even though i added the salt column again , i think the encryption is handled in the password ()
is different from how User passwords are encrypted in db currently .
as i tested in the bench mariadb , the password function uses mda5 or sha1 , while all the passwords in the password field of auth table are encrypted in sha256 .
So
- How can i verify if a password is similar to one in database ?
- is there any easier way to achieve this now , or this is way is already optimal ?
Thanks