There are various encryption options available for PHP where some of them are explained nicely in the following question:
How do you Encrypt and Decrypt a PHP String?
The updated and accepted answer gives a nice, working example with openssl_encrypt function from PHP OpenSSL Library.
But when I tested the code, I noticed the encrypted string is always different when you want to recreate the encrypted string while using the same ENCRYPTION_KEY.
While this may be useful for applications like network communication, I need a solution where the encrypted string can be obtained as same for the same encryption key.
I am planning to use it for user authentication with userid and password. I will be using the userid (together with some padded characters) as the encryption key and store it in MySQL DB as encyrpted.
During the authentication, I DO NOT WANT TO DECRYPT the stored password to compare with the entered password. I do not want at any time the stored password to be seen in clear. Just compare encrypted string with stored (encrypted) password. This of course needs the encrypted string to be the same for all encryptions.
Is there a way, an option, a parameter setting or anything else to get a UNIQUE encrypted string?