{"id":49455,"date":"2024-12-02T15:46:57","date_gmt":"2024-12-02T07:46:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49455\/"},"modified":"2024-12-02T15:46:57","modified_gmt":"2024-12-02T07:46:57","slug":"lithe-hash%ef%bc%9a%e7%94%a8%e4%ba%8e%e5%ae%89%e5%85%a8%e5%af%86%e7%a0%81%e5%93%88%e5%b8%8c%e7%9a%84%e5%bc%ba%e5%a4%a7%e6%a8%a1%e5%9d%97-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49455\/","title":{"rendered":"Lithe Hash\uff1a\u7528\u4e8e\u5b89\u5168\u5bc6\u7801\u54c8\u5e0c\u7684\u5f3a\u5927\u6a21\u5757"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Lithe Hash\uff1a\u7528\u4e8e\u5b89\u5168\u5bc6\u7801\u54c8\u5e0c\u7684\u5f3a\u5927\u6a21\u5757<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aLithe Hash\uff1a\u7528\u4e8e\u5b89\u5168\u5bc6\u7801\u54c8\u5e0c\u7684\u5f3a\u5927\u6a21\u5757\u300b<\/span>\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241202\/1733111688674d2f888dedd.jpg\" class=\"aligncenter\" title=\"Lithe Hash\uff1a\u7528\u4e8e\u5b89\u5168\u5bc6\u7801\u54c8\u5e0c\u7684\u5f3a\u5927\u6a21\u5757\u63d2\u56fe\" alt=\"Lithe Hash\uff1a\u7528\u4e8e\u5b89\u5168\u5bc6\u7801\u54c8\u5e0c\u7684\u5f3a\u5927\u6a21\u5757\u63d2\u56fe\" \/><\/p>\n<p><strong>lithe hash<\/strong> \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6a21\u5757\uff0c\u8bbe\u8ba1\u7528\u4e8e\u4f7f\u7528 bcrypt \u7b97\u6cd5\u5b89\u5168\u5730\u6563\u5217\u5bc6\u7801\u3002\u8be5\u6a21\u5757\u7b80\u5316\u4e86\u521b\u5efa\u3001\u9a8c\u8bc1\u548c\u7ba1\u7406\u5bc6\u7801\u54c8\u5e0c\u7684\u8fc7\u7a0b\uff0c\u786e\u4fdd\u9075\u5faa\u5b89\u5168\u6700\u4f73\u5b9e\u8df5\u3002<\/p>\n<h2> \u76ee\u5f55 <\/h2>\n<ol>\n<li>\u5b89\u88c5<\/li>\n<li> \u7528\u6cd5\n<ul>\n<li>\u5bfc\u5165\u7c7b<\/li>\n<li>\u521b\u5efa\u54c8\u5e0c<\/li>\n<li>\u9a8c\u8bc1\u54c8\u5e0c<\/li>\n<li>\u68c0\u67e5\u54c8\u5e0c\u662f\u5426\u9700\u8981\u91cd\u65b0\u54c8\u5e0c<\/li>\n<li>\u4e86\u89e3 bcrypt<\/li>\n<li>\u5904\u7406\u5f02\u5e38<\/li>\n<\/ul>\n<\/li>\n<li>\u6d4b\u8bd5<\/li>\n<li>\u8bb8\u53ef\u8bc1<\/li>\n<\/ol>\n<h2> \u5b89\u88c5 <\/h2>\n<p>\u8981\u5b89\u88c5 lithemod\/hash \u5305\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 composer\u3002\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>composer require lithemod\/hash\n<\/pre>\n<p>\u8fd9\u4f1a\u5c06\u5305\u6dfb\u52a0\u5230\u60a8\u7684\u9879\u76ee\u7684\u4f9d\u8d56\u9879\u4e2d\uff0c\u4ece\u800c\u5141\u8bb8\u60a8\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528 hash \u7c7b\u3002<\/p>\n<h2> \u7528\u6cd5 <\/h2>\n<h3> \u5bfc\u5165\u7c7b <\/h3>\n<p>\u5728\u4f7f\u7528 hash \u7c7b\u4e4b\u524d\uff0c\u60a8\u5fc5\u987b\u5c06\u5176\u5bfc\u5165 php \u6587\u4ef6\u4e2d\uff1a<\/p>\n<pre>use lithe\\support\\security\\hash;\n<\/pre>\n<h3> \u521b\u5efa\u54c8\u5e0c <\/h3>\n<p>\u8981\u4ece\u5bc6\u7801\u521b\u5efa\u54c8\u5e0c\uff0c\u8bf7\u4f7f\u7528 make \u65b9\u6cd5\u3002\u8be5\u65b9\u6cd5\u63a5\u53d7\u5bc6\u7801\u548c\u53ef\u9009\u9009\u9879\u6570\u7ec4\uff1a<\/p>\n<pre>$hash = hash::make('your_password', ['cost' =&gt; 10]);\n<\/pre>\n<p><strong>\u53c2\u6570\uff1a<\/strong><\/p>\n<ul>\n<li> string $value\uff1a\u8981\u54c8\u5e0c\u7684\u5bc6\u7801\u3002<\/li>\n<li> array $options: \u7528\u4e8e\u8c03\u6574\u54c8\u5e0c\u7b97\u6cd5\u7684\u53ef\u9009\u53c2\u6570\uff08\u4f8b\u5982\u6210\u672c\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u8fd4\u56de\uff1a<\/strong> \u53ef\u4ee5\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\u7684\u54c8\u5e0c\u5b57\u7b26\u4e32\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>$password = 'my_secure_password';\n$hash = hash::make($password, ['cost' =&gt; 12]);\necho \"hashed password: \" . $hash;\n<\/pre>\n<h3> \u9a8c\u8bc1\u54c8\u5e0c\u503c <\/h3>\n<p>\u8981\u68c0\u67e5\u7ed9\u5b9a\u7684\u5bc6\u7801\u662f\u5426\u4e0e\u54c8\u5e0c\u503c\u5339\u914d\uff0c\u8bf7\u4f7f\u7528\u68c0\u67e5\u65b9\u6cd5\uff1a<\/p>\n<pre>$isvalid = hash::check('your_password', $hash);\nif ($isvalid) {\n    echo 'password is valid!';\n} else {\n    echo 'invalid password.';\n}\n<\/pre>\n<p><strong>\u53c2\u6570\uff1a<\/strong><\/p>\n<ul>\n<li> string $value: \u8981\u9a8c\u8bc1\u7684\u5bc6\u7801\u3002<\/li>\n<li> string $hash\uff1a\u8981\u6bd4\u8f83\u7684\u54c8\u5e0c\u5bc6\u7801\u3002<\/li>\n<\/ul>\n<p><strong>\u8fd4\u56de\uff1a<\/strong> \u5982\u679c\u5bc6\u7801\u4e0e\u54c8\u5e0c\u503c\u5339\u914d\uff0c\u5219\u8fd4\u56de true\uff1b\u5426\u5219\u4e3a false\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>if (hash::check('my_secure_password', $hash)) {\n    echo 'password is correct!';\n} else {\n    echo 'password is incorrect!';\n}\n<\/pre>\n<h3> \u68c0\u67e5\u54c8\u5e0c\u662f\u5426\u9700\u8981\u91cd\u65b0\u54c8\u5e0c <\/h3>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528needsrehash\u65b9\u6cd5\u786e\u5b9a\u54c8\u5e0c\u662f\u5426\u9700\u8981\u91cd\u65b0\u6563\u5217\uff08\u4f8b\u5982\uff0c\u662f\u5426\u66f4\u6539\u6210\u672c\u56e0\u5b50\uff09\uff1a<\/p>\n<pre>$needsrehash = hash::needsrehash($hash, ['cost' =&gt; 14]);\nif ($needsrehash) {\n    \/\/ rehash with a new cost\n    $hash = hash::make('your_password', ['cost' =&gt; 14]);\n}\n<\/pre>\n<p><strong>\u53c2\u6570\uff1a<\/strong><\/p>\n<ul>\n<li> string $hash\uff1a\u8981\u8bc4\u4f30\u7684\u54c8\u5e0c\u5bc6\u7801\u3002<\/li>\n<li> array $options: \u53ef\u9009\u53c2\u6570\uff0c\u7528\u4e8e\u6307\u5b9a\u6210\u672c\u3002<\/li>\n<\/ul>\n<p><strong>\u8fd4\u56de\uff1a<\/strong> \u5982\u679c\u54c8\u5e0c\u503c\u9700\u8981\u91cd\u65b0\u54c8\u5e0c\uff0c\u5219\u8fd4\u56de true\uff1b\u5426\u5219\u4e3a false\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>if (hash::needsrehash($hash, ['cost' =&gt; 15])) {\n    $hash = hash::make('my_secure_password', ['cost' =&gt; 15]);\n    echo \"rehashed password: \" . $hash;\n}\n<\/pre>\n<h3> \u4e86\u89e3 bcrypt <\/h3>\n<p>bcrypt \u662f\u4e00\u79cd\u5e7f\u6cdb\u4f7f\u7528\u7684\u5bc6\u7801\u54c8\u5e0c\u51fd\u6570\uff0c\u5176\u8bbe\u8ba1\u901f\u5ea6\u6162\u4e14\u8ba1\u7b97\u5bc6\u96c6\uff0c\u4f7f\u5176\u80fd\u591f\u62b5\u6297\u66b4\u529b\u653b\u51fb\u3002\u901a\u8fc7\u4f7f\u7528\u53ef\u914d\u7f6e\u7684\u6210\u672c\u7cfb\u6570\uff0cbcrypt \u5141\u8bb8\u60a8\u968f\u7740\u786c\u4ef6\u53d8\u5f97\u66f4\u5feb\u800c\u589e\u52a0\u54c8\u5e0c\u96be\u5ea6\u3002<\/p>\n<ul>\n<li> <strong>\u6210\u672c\u56e0\u7d20\uff1a<\/strong>\u6210\u672c\u56e0\u7d20\u51b3\u5b9a\u4e86\u6563\u5217\u5bc6\u7801\u7684\u8ba1\u7b97\u590d\u6742\u6027\u3002\u5b83\u8868\u793a\u54c8\u5e0c\u7b97\u6cd5\u7684\u8fed\u4ee3\u6b21\u6570\u3002\u66f4\u9ad8\u7684\u6210\u672c\u610f\u5473\u7740\u66f4\u9ad8\u7684\u5b89\u5168\u6027\uff0c\u4f46\u4e5f\u4f1a\u589e\u52a0\u5904\u7406\u65f6\u95f4\u3002\u5bf9\u4e8e\u5927\u591a\u6570\u5e94\u7528\uff0c\u5efa\u8bae\u7684\u8303\u56f4\u662f 10 \u5230 12 \u4e4b\u95f4\u3002<\/li>\n<\/ul>\n<h3> \u5904\u7406\u5f02\u5e38 <\/h3>\n<p>\u5982\u679c\u6210\u672c\u8bbe\u7f6e\u8d85\u51fa\u6709\u6548\u8303\u56f4\uff084 \u5230 31\uff09\uff0c\u5219 make \u65b9\u6cd5\u4f1a\u629b\u51fa invalidargumentexception\u3002\u60a8\u5e94\u8be5\u5728\u4ee3\u7801\u4e2d\u5904\u7406\u6b64\u95ee\u9898\u4ee5\u786e\u4fdd\u7a33\u5065\u6027\uff1a<\/p>\n<pre>try {\n    $hash = Hash::make('your_password', ['cost' =&gt; 3]); \/\/ Invalid cost\n} catch (\\InvalidArgumentException $e) {\n    echo \"Error: \" . $e-&gt;getMessage();\n}\n<\/pre>\n<hr>\n<p>\u501f\u52a9 <strong>lithe hash<\/strong>\uff0c\u60a8\u53ef\u4ee5\u5b89\u5168\u9ad8\u6548\u5730\u7ba1\u7406\u5bc6\u7801\uff0c\u540c\u65f6\u9075\u5faa\u5b89\u5168\u6700\u4f73\u5b9e\u8df5\u3002\u5982\u679c\u60a8\u6709\u4efb\u4f55\u7591\u95ee\u6216\u5efa\u8bae\uff0c\u8bf7\u968f\u65f6\u8bc4\u8bba\uff01<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aLithe Hash\uff1a\u7528\u4e8e\u5b89\u5168\u5bc6\u7801\u54c8\u5e0c\u7684\u5f3a\u5927\u6a21\u5757\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n<p> \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lithe Hash\uff1a\u7528\u4e8e\u5b89\u5168\u5bc6\u7801\u54c8\u5e0c\u7684\u5f3a\u5927\u6a21\u5757 \u6536\u85cf \u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0\u300aLithe Hash\uff1a\u7528\u4e8e\u5b89\u5168\u5bc6\u7801\u54c8\u5e0c\u7684\u5f3a\u5927\u6a21\u5757\u300b\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01 lithe hash \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6a21\u5757\uff0c\u8bbe\u8ba1\u7528\u4e8e\u4f7f\u7528 bcrypt \u7b97\u6cd5\u5b89\u5168\u5730\u6563\u5217\u5bc6\u7801\u3002\u8be5\u6a21\u5757\u7b80\u5316\u4e86\u521b\u5efa\u3001\u9a8c\u8bc1\u548c\u7ba1\u7406\u5bc6\u7801\u54c8\u5e0c\u7684\u8fc7\u7a0b\uff0c\u786e\u4fdd\u9075\u5faa\u5b89\u5168\u6700\u4f73\u5b9e\u8df5\u3002 \u76ee\u5f55 \u5b89\u88c5 \u7528\u6cd5 \u5bfc\u5165\u7c7b \u521b\u5efa\u54c8\u5e0c \u9a8c\u8bc1\u54c8\u5e0c \u68c0\u67e5\u54c8\u5e0c\u662f\u5426\u9700\u8981\u91cd\u65b0\u54c8\u5e0c \u4e86\u89e3 bcrypt \u5904\u7406\u5f02\u5e38 \u6d4b\u8bd5 \u8bb8\u53ef\u8bc1 \u5b89\u88c5 \u8981\u5b89\u88c5 lithemod\/hash \u5305\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 composer\u3002\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a composer require lithemod\/hash \u8fd9\u4f1a\u5c06\u5305\u6dfb\u52a0\u5230\u60a8\u7684\u9879\u76ee\u7684\u4f9d\u8d56\u9879\u4e2d\uff0c\u4ece\u800c\u5141\u8bb8\u60a8\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528 hash \u7c7b\u3002 \u7528\u6cd5 \u5bfc\u5165\u7c7b \u5728\u4f7f\u7528 hash \u7c7b\u4e4b\u524d\uff0c\u60a8\u5fc5\u987b\u5c06\u5176\u5bfc\u5165 php \u6587\u4ef6\u4e2d\uff1a use lithe\\support\\security\\hash; \u521b\u5efa\u54c8\u5e0c \u8981\u4ece\u5bc6\u7801\u521b\u5efa\u54c8\u5e0c\uff0c\u8bf7\u4f7f\u7528 make \u65b9\u6cd5\u3002\u8be5\u65b9\u6cd5\u63a5\u53d7\u5bc6\u7801\u548c\u53ef\u9009\u9009\u9879\u6570\u7ec4\uff1a $hash = hash::make(&#8216;your_password&#8217;, [&#8216;cost&#8217; =&gt; 10]); \u53c2\u6570\uff1a string $value\uff1a\u8981\u54c8\u5e0c\u7684\u5bc6\u7801\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-49455","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=49455"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49455\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}