{"id":25974,"date":"2024-11-24T09:29:25","date_gmt":"2024-11-24T01:29:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25974\/"},"modified":"2024-11-24T09:29:25","modified_gmt":"2024-11-24T01:29:25","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","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25974\/","title":{"rendered":"Lithe Hash\uff1a\u7528\u4e8e\u5b89\u5168\u5bc6\u7801\u54c8\u5e0c\u7684\u5f3a\u5927\u6a21\u5757"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173076824464912.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 \u3002\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>composer require lithemod\/hash\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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 lithesupportsecurityhash;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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>\u4ee5\u4e0a\u5c31\u662fLithe Hash\uff1a\u7528\u4e8e\u5b89\u5168\u5bc6\u7801\u54c8\u5e0c\u7684\u5f3a\u5927\u6a21\u5757\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 \u3002\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a composer require lithemod\/hash \u767b\u5f55\u540e\u590d\u5236 \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 lithesupportsecurityhash; \u767b\u5f55\u540e\u590d\u5236 \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]); \u767b\u5f55\u540e\u590d\u5236 \u53c2\u6570\uff1a string $value\uff1a\u8981\u54c8\u5e0c\u7684\u5bc6\u7801\u3002 array $options: [&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-25974","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25974","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=25974"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25974\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}