Encrypting and decrypting in PHP

The crypt() function provide one-way encryption. Using one-way encryption is like using a key to lock and unlock something. The key is your password.

To encrypt:

$pass = 'secret';
$encrypted = crypt($pass);
// $encrypted = $1$zaxz8vXb$.lZaoK40w/EtrkkogORYo0

To decrypt:

// entered password
$pass = 'secret';
// $password is the encrypted password
if (crypt($pass, $encrypted) == $encrypted) {
  print 'welcome';
} else {
  print 'wrong password';
}
Technologies: