The best way to make sure your encrypted text will not be decrypted when it has been modified is to add an authentication tag. An authentication tag is used to ensure the authentication and integrity of ciphertext.
This tag can consist of a MAC (for example, AES-CMAC or HMAC using SHA-256) in encrypted text. However, this requires a second key.
Another method is to use authenticated encryption such as GCM. GCM uses a single key and generates an authentication tag (size can be customized).
Make sure you are using a properly generated IV. IV may be a prefix for the ciphertext and should be included when calculating the authentication tag), and do not forget that the size of your plain text may not be hidden.
You must verify that the tag is correct before decrypting the ciphertext.
Please note that in general, you should not encrypt passwords unless you need access to the exact password later. To verify passwords, use PBKDF2 instead.
source share