defuse / php-encryption

Simple Encryption in PHP.
MIT License
3.78k stars 308 forks source link

Decrypt data when user change password #499

Closed suwidadi closed 1 year ago

suwidadi commented 1 year ago

Hi, I'm trying to use the userPassword scenario and I found confusion when the user change the password after the initial key was saved. is there any suggestion for unlocking the saved key when the user changes the password? is there any method to update the key and decrypt saved encrypted data?

defuse commented 1 year ago

You want to use the changePassword method of KeyProtectedByPassword to change the password, then save the new KeyProtectedByPassword that you get from doing that:

https://github.com/defuse/php-encryption/blob/master/docs/classes/KeyProtectedByPassword.md#changepasswordcurrent_password-new_password