I believe what you're looking for is a way to encrypt and decrypt the password. There are algorithms that allow you to encrypt a string and reverse the encrypted string to get the original one: Encryption algorithms, while some do not: Hashing algorithms
Since you're using PHP, you can use the in-built function openssl_encrypt
to encrypt and openssl_decrypt
to decrypt it
string openssl_encrypt(
string $data, string $method, string $key,
$options = 0, string $iv, string $tag= NULL,
string $aad, int $tag_length = 16
)
# Returns a boolean
string openssl_decrypt(
string $data, string $method, string $key,
int $options = 0, string $iv, string $tag, string $aad
)
Example:
$string = "My password";
$ciphering = "AES-128-CTR";
$options = 0;
$encryption_iv = '1234567891011121';
$encryption_key = "YOURCUSTOMKEY";
$encryption = openssl_encrypt($string, $ciphering, $encryption_key, $options, $encryption_iv);
$decryption_iv = $encryption_iv;
$decryption_key = $encryption_key;
$decryption = openssl_decrypt($encryption, $ciphering, $decryption_key, $options, $decryption_iv);
echo "Original => " . $string;
echo '<br/>';
echo "Encrypted => " . $encryption . "\n";
echo '<br/>';
echo "Decrypted => " . $decryption;
For this to work, the key you use to decrpyt should be the same as the one used to encrypt or the results will be different. So the key $encryption_key
should be not accessible to anyone else.