从互联网上窃取的Bcrypt类,适用于Composer。

0.3.3 2013-02-25 21:01 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:49:37 UTC


README

BitBucket分叉(来自我自己)。

这是我个人使用的Bcrypt包装类,我在项目中使用它来加密业务。大部分代码不是我写的——请在文件注释中查看我归功于所有的人。话虽如此,网上有无数的文件和这个文件完全一样,但名字不同。人民的Bcrypt迷你库...东西。

它基于StackOverflow上Andrew Moore的答案。如果你使用PHP 5.5或更高版本,请使用password_hash代替。

风险自负。我对这个库的加密奇妙之处提供绝对没有保证,原始作者可能也是如此...

用法

使用便利函数来进行简单的散列和散列验证。

$hashed = \Bcrypt\hash('this is a random string');

// elsewhere...

$plain_text_password = //... 

if (\Bcrypt\verify($plain_text_password, $user_pass_hash)) {
  login();
}

为了更精细的控制,实例化一个Bcrypt对象

// Control the prefix, number of rounds...
$bcrypt = new \Bcrypt\Bcrypt('prefix', 15);

// And use the instance to produce many hashes.
$hashes[] = $bcrypt->hash('this is a string');
$hashes[] = $bcrypt->hash('this is another string');

// You can also do this:

if ($bcrypt->verify($plain_text_password, $user_pass_hash)) {
  login();
}

Composer

如果你使用Composer,你只需将其添加到你的require列表中

{
    "require": {
        "eddieantonio/bcrypt": "0.3.0"
    }
}

许可证

Creative Commons Public Domain Declaration

由于代码的主体是从各种来源窃取的,这些来源只是将代码发布到互联网上而没有许可证,我考虑这个库默认属于公共领域,并且不为此代码的编写署名;只是将其打磨得可以很容易地与Composer一起使用。