Decrypting a user password

Hi good day. I’m currently working a validation for user which they will enter their password in a document and will check if it is correct but unfortunately an error is showing evrytime I use frappe.utils.password methods like get get_decrypted_password and decrypt. Can anyone help me with this? Btw I’d posted a screen shot of what the error is.

image
image
image

Hi @Rabie_Moses_Santilla for what i know, your site encryption_key is different from the ones that you used on saving that data. You have 2 options:

  1. Try to find the old encryption_key you had. It located on frappe-bench>sites>//ur_site_name//>site_config.json. After that replace the error site you have, with the old encryption_key. Don’t forget to backup/copy the existing encryption_key in case somehing goes wrong.
    *Note be carefull with this method, that ur password data that saved after using new encryption key will have error like you had too.
    image
  2. Resave that document with new password. So the password encrypted with your existing encryption_key.

Thanks for the reply. I have difficulty in retrieving the old encryption key so what I did is I created a new user. Could I now retrieve the password of the new user using the new encryption key? Btw do you know how to use the decrypt() method in the frappe.utils.password.py? I’m using it now to extract the plain text password but maybe I am using it wrong… here is my code…

@Rabie_Moses_Santilla User passwords are hashed using PBKDF2, not encrypted. You can’t recover the original password from the hashes for comparison, you can only verify if the password provided by the client matches the stored hash.

Please refer to check_password and update_password in frappe.utils.password

set_encrypted_password, get_decrypted_password are used for storing/retrieving credentials (Password/Secret Key/Access Token etc.) of other services e.g. Email Account, Dropbox, AWS S3 etc.

6 Likes