Php-mysql Course

The openssl_encrypt() and openssl_decrypt() functions can be used to encrypt and decrypt text in PHP.
They are useful to encrypt and decrypt the user password in a register /login script.

- Here is a simple example with the openssl_encrypt() and openssl_decrypt() functions.
$password = 'user_pass'; //password added by user $_POST['password']
$key_enc = '1234'; //key for encrypt
$met_enc = 'aes256'; //method to encrypt: aes128, aes192, aes256, blowfish, cast-cbc
$iv = '16_characters_ok'; //a random string with 16 characters

//encrypts the password
$pass_enc = openssl_encrypt($password, $met_enc, $key_enc, 0, $iv);
echo $pass_enc; // "uw4QKRUsG+l17w5epb7nKw=="

//decrypts the encrypted password, it uses the same arguments: $met_enc, $key_enc, $opt=0, $iv
$pass_enc ='uw4QKRUsG+l17w5epb7nKw=='; //the encrypted password
$pass = openssl_decrypt($pass_enc, $met_enc, $key_enc, 0, $iv);
echo '<br>'.$pass; // "user_pass"

Notice, the openssl_decrypt() must use the same arguments (here: $met_enc, $key_enc, $opt=0, $iv) to decrypt the string encrypted with openssl_encrypt().

Daily Test with Code Example

Which type of <input> creates a color well control for selecting a color value?
type="text" type="color" type="date"
<input type="color" name="get_color" />
Which CSS method rotates the HTML element at a given degree?
scale() translate() rotate()
#some_id:hover {
  transform: rotate(60deg);
  -ms-transform: rotate(60deg);    /* IE 9 */
  -moz-transform: rotate(60deg);   /* Firefox */
Click on the function that returns the number with the highest value.
pow() min() max()
var maxn = Math.max(8, 4, 88, 56);
alert(maxn);      // 88
Which function prevent the same file from being included more than once in a page?
include() include_once() require()
Using openssl_encrypt and openssl_decrypt in PHP

Last accessed pages

  1. Move image from an element /tag to another (2502)
  2. Awareness - by Anthony de Mello (5866)
  3. Get the Height and Width of web Page and browser Window (3094)
  4. Simple PHP Upload Script (7775)
  5. Add Text in Canvas from Input text field, as it is Typed (9084)

Popular pages this month

  1. PHP Unzipper - Extract Zip, Rar Archives (186)
  2. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (158)
  3. Read Excel file data in PHP - PhpExcelReader (94)
  4. SHA1 Encrypt data in JavaScript (86)
  5. SHA256 Encrypt hash in JavaScript (86)