Introduction
Encryption is the conversion of data into a form called "ciphertext", that cannot be easily understood by unauthorized people. Decryption is the reverse of encryption; it decrepts the data that had been encrypted.
In PHP we can use the "crypt()" function to create a one-way encryption. Often in an application a password is confidential for the user. When the user chooses their password, the password is then encrypted, and the encrypted version of the password is saved. Whenever the user logins the next time, the application provides the login facilities; if their password matches the encrypted version of the saved password then the login is successful.
Syntax
The syntax of the crypt function is:
| crypt (inputString, Salt) |
Parameters
The parameters for the crypt function are:
| Parameter | Description |
| inputString | It specifies which string, you would like to encrypt (Example- Password). |
| Salt | The optional parameter Salt specifies , how encryption will work. Salt will work four types:
|
Example
The following example shows how you can decrypt your input string (like a NewPassword) in various ways. If you do not use the second encrypt function parameter (Salt), the encrypt inputString will be different every time that the crypt function is executed. If you use the same salt then the encrypted password should always be the same.
<?php
$encryptpassword = crypt('NewPassword');
print $encryptpassword . "is the <b>encrypted version</b> of mypassword.";
echo "</br>";
$encryptpassword = crypt('NewPassword' , 'rtw34');
print $encryptpassword . " is the <b>CRYPT_STD_DES version</b> of mypassword"."</br>";
$password = crypt('NewPassword' , 'k7uritrd.y1g');
print $encryptpassword . " is the <b>CRYPT_EXT_DES version</b> of mypassword."."</br>";
$encryptpassword = crypt('NewPassword' , '$1$d5rttuhy6d$');
print $encryptpassword . " is the <b>CRYPT_MD5 version</b> of mypassword."."</br>";
$encryptpassword = crypt('NewPassword' , '$2a$07$khgfslerd...........$');
print $encryptpassword . " is the <b>CRYPT_BLOWFISH version</b> of mypassword.";
?>
Output

Sharad GuptaeditedPosted Feb 2, 2013, 2:42 AMEdited Feb 2, 2013, 2:43 AM
Hi Vineet ,Often passwords are HASHED before being put into a database, as opposed to ENCRYPTED. The difference is that a hashing function has a one to many relationship between the original text and the result text. This makes it impossible to directly gather the original text when given the hash. MD5 hashing functions. Let us suppose you are admin and you have accessibility to modify data from database. Then firstly you will try to find out which algorithm or technique is used to encrypt the password, suppose you write base64_encode () function to encrypt user password, then you have also base64_decode() function to decryption this password. For example <?php $key = "Mypwd"; $enc = base64_encode ($key); $dec = base64_decode ($enc); ?> But if you used the technique like (MD5), then there is no way to decrypt the password, because this is one way encryption technique. You can easily reset the password by another encryption technique, which have already decryption algorithm, and new password sent to user.
Vineet Kumar SainiPosted Feb 2, 2013, 12:17 AM
Hi Sharad, i want to know how to decrypt password from the database in php.