The following code encrypts a string.

$password = "password";
$encryptedPassword = crypt($password);
print $encryptedPassword

crypt() function encrypts the string. The last line prints the encrypted string.

There is no such function called decrypt(). This is because crypt uses a one-way encryption algorithm. This basically means that you can encrypt a string but can not decrypt it to get back the original string. If you can’t see the original password that was encrypted, then how can you compare a password to make sure that it is a valid password. The answer is that you encrypt the string you want to compare it to and then compare the encryptions. Here is how you match the strings.

$verifyPassword = crypt($password,$encryptedPassword);

$verifyPassword = crypt($password, $encryptedPassword);
if ($verifyPassword == $encryptedPassword)
   echo "Password is valid";
   echo "Invalid Password";

I know that I skipped over a lot of things, but the purpose of this article to simply get you started easily and quickly.