定制 insomnius/aurphm 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

insomnius/aurphm

Composer 安装命令:

composer require insomnius/aurphm

包简介

Aurelia pseudo hashing method is my experimental function to hash password with HMAC (Hash-based message authentication code), PBKDF2 (Password-Based Key Derivation Function 2) and Pseudo Random Bytes.

README 文档

README

Aurelia pseudo hashing method (Aurphm) is my experimental function to hash password with HMAC (Hash-based message authentication code), PBKDF2 (Password-Based Key Derivation Function 2) and Pseudo Random Bytes. The main reason to create this library is to make good hash for security reason and the hash must be:

  • Has a random salt every hash generation
  • Has a user unique hash so it will generate differently if the key and credential is different using HMAC
  • Has a unique signature for authentication using PBKDF2
  • Has a different hash value every hash generation but still can be authenticated
  • We can set their prefered algorithm for each method (salt, user unique, signature)
  • Simple to authenticate

This library is inspired by a post in crackstation about how to make secure hash here.

How to use

Here is a simple step to generate a hash:

	use Aurphm\Aurphm;

	$credential = "credential";
	$key = "key";

	$hash = Aurphm::hash($credential, $key);
	
	echo $hash;

The hash result will be random every generation and the one of the result is:

hash-result-example

And there is an advanced configuration too, you can change how much iteration on PBKDF, the prefix, signature length, salt algorithm, algorithm for creating user unique hash and algorithm for signature.

Here is the example code:

    $credential = 'credential';
	$key = 'key';
    $length = 128;
    $iteration = 64;
    $prefix = 'GITHUB';
    
    $saltalgo = 'SHA1';
    $useruniquealgo = 'SHA256';
    $signaturealgo = 'MD5';
    
    $hash = Aurphm::init()->setIteration($iteration) // You have to use ini to called this function statically, Set the iteration of pbkdf
                ->setPrefix($prefix) // Set the prefix of the hash
                ->setSignatureLength($length) // Set signature length
                ->setSaltAlgo($saltalgo) // Set salt hash algorithm
                ->setUserUniqueAlgo($useruniquealgo) // Set user unique hash algorithm (hmac algorithm)
                ->setSignatureAlgo($signaturealgo) // Set signature hash algorithm (pbkdf algorithm)
                ->hash($credential, $key);
    
    echo $hash;

And here is the result look like:

hash-result-advanced-example

And lastly, how about authenticate? we can do that in simple way too like this:

$hash_value = 'AURPHM_e61ab31BBLABLABLABLABLABLABLABLA';
$key = 'key';
$credential = 'credential';

if(Aurphm::authenticate($credential, $key, $hash_value))
{
    echo "Authentication success!";
}
else
{
    echo "Authentication failed.";
}

Download

You can download this package via github release or if you using composer just type this and the magic will do the work.

composer require insomnius/aurphm

Demo

You can also view the demo i made in demo folder using php development server, just type this in your command prompt or terminal (make sure you are in the root directory of this project):

php -S localhost:7800 -t ./demo/

And then open your browser with address http://localhost:7800.

That's it, have fun to use it! :)

统计信息

  • 总下载量: 647
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 13
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-01-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固