polarising/bcrypt

Customized Bcrypt for PHP

1.0.2 2016-11-22 05:16 UTC

This package is auto-updated.

Last update: 2024-12-11 20:18:47 UTC


README

========

Build Status Latest Stable Version Latest Unstable Version Total Downloads License Scrutinizer Code Quality

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.

Installing Bcrypt

The recommended way to install Bcrypt is through Composer.

# Install Composer
curl -sS https://getcomposer.org/installer | php

Next, run the Composer command to install the latest stable version of Bcrypt:

php composer.phar require polarising/bcrypt

After installing, you need to require Composer's autoloader:

require 'vendor/autoload.php';

You can then later update Bcrypt using composer:

composer.phar update

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!");
}