# bcrypt
, (*1)
Instead of using PHP hash password API, encrypt plain text by using Bcrypt algorithm, and make sure it's compatible with Bcrypt in other programming languages, like Java, python., (*2)
Installing Bcrypt
The recommended way to install Bcrypt is through
Composer., (*3)
# Install Composer
curl -sS https://getcomposer.org/installer | php
Next, run the Composer command to install the latest stable version of Bcrypt:, (*4)
php composer.phar require polarising/bcrypt
After installing, you need to require Composer's autoloader:, (*5)
require 'vendor/autoload.php';
You can then later update Bcrypt using composer:, (*6)
bash
composer.phar update, (*7)
Quick Examples
Encrypt Plaintext, Verify Plaintext and Ciphertext
<?php
// Require the Composer autoloader.
require 'vendor/autoload.php';
use Bcrypt\Bcrypt;
// Instantiate an Bcrypt instance.
$bcrypt = new Bcrypt();
//Encrypt the plaintext
$plaintext = 'password';
//Set the Bcrypt Version, default is '2y'
$bcrypt_version = '2a';
$ciphertext = $bcrypt->encrypt($plaintext,$bcrypt_version);
print_r("\n Plaintext:".$plaintext);
print_r("\n Ciphertext:".$ciphertext);
//Verify the plaintext and ciphertext
if($bcrypt->verify($plaintext, $ciphertext)){
print_r("\n Password verified!");
}else{
print_r("\n Password not match!");
}