On a website, I would like to implement a system where users can message each other. The content of the messages should be protected against attackers that are trying to read them.
My first thought was to use a public/private key pair for each user and encrypt the private key with the password of the user. In this way, a hacker gaining access to the database would not be able to decrypt the messages.
On the other hand, users frequently forget their passwords and need to reset them. This would then have the effect that all past messages are lost.
There is probably a better solution for the whole process and I am just thinking in the wrong direction. Can somebody guide me?