It is very unfortunate that you have encountered such a problem. In order to avoid account hacking, you need to keep your accounts confidential. No software is 100% secure. However, storing your logins and other sensitive information in a password manager is much safer than memorizing simple passwords or writing them down in an encrypted file on your Mac. To learn how to do this correctly and which programs to use, visit
https://setapp.com/how-to/best-password-managers-for-mac, where everything is described in detail about security.