Commit d2f1f6cf authored by 康帅杰's avatar 康帅杰 :speech_balloon:
Browse files

迁移过来

parent 55e900e9
No related merge requests found
Showing with 77 additions and 0 deletions
+77 -0
{
"name": "yjtec/pwd",
"description": "pwd check create",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "kidkang",
"email": "723616880@qq.com"
}
],
"autoload": {
"psr-4": {
"Yjtec\\Pwd\\":"src/"
}
},
"minimum-stability": "dev",
"require": {
"yjtec/support": "1.0.*"
},
"require-dev": {
}
}
<?php
require __DIR__.'/../vendor/autoload.php';
use Yjtec\Pwd\Pwd;
$re = Pwd::build('123123');
echo Pwd::check('123123','6b1d6a0d582c994cf8b9fba3b2928149','Op32q5iZ');
print_r($re);
\ No newline at end of file
<?php
namespace Yjtec\Pwd;
use Yjtec\Support\Str;
class Pwd
{
/**
* [生成密码]
* @param [type] $pwd [原始密码]
* @param boolean $is_md5 [description]
* @return [type] [description]
*/
public static function build($pwd, $is_md5 = false)
{
$salt = Str::random(8);
$pwd = $is_md5 ? $pwd : md5($pwd);
$pwd = md5($pwd . $salt);
return [
'pwd' => $pwd,
'salt' => $salt,
];
}
/**
* 验证密码的正确
* @param [type] $pwd [输入的密码]
* @param [type] $rpwd [数据库密码]
* @param [type] $salt [盐池]
* @param boolean $is_md [是否md5加密]
* @return [type] [bool 密码是否相等]
*/
public static function check($pwd, $rpwd, $salt, $is_md5 = false)
{
$pwd = $is_md5 ? $pwd : md5($pwd);
$pwd = md5($pwd . $salt);
return $pwd === $rpwd;
}
}
<?php
use PHPUnit\Framework\TestCase;
class PwdTest extends PHPUnit_Framework_TestCase{
public function testCanBuildPwd(){
}
}
?>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment