{"id":48414,"date":"2024-12-02T15:02:58","date_gmt":"2024-12-02T07:02:58","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48414\/"},"modified":"2024-12-02T15:02:58","modified_gmt":"2024-12-02T07:02:58","slug":"%e4%bd%bf%e7%94%a8-password_hash-%e6%95%a3%e5%88%97%e5%af%86%e7%a0%81%e5%90%8e%ef%bc%8c%e4%b8%ba%e4%bb%80%e4%b9%88%e9%aa%8c%e8%af%81%e6%97%b6%e8%be%93%e5%85%a5%e7%9a%84%e5%af%86%e7%a0%81%e4%bc%bc","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48414\/","title":{"rendered":"\u4f7f\u7528 `password_hash()` \u6563\u5217\u5bc6\u7801\u540e\uff0c\u4e3a\u4ec0\u4e48\u9a8c\u8bc1\u65f6\u8f93\u5165\u7684\u5bc6\u7801\u4f3c\u4e4e\u4e0d\u5339\u914d\uff0c\u4f46\u4ecd\u7136\u6210\u529f\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u4f7f\u7528 `password_hash()` \u6563\u5217\u5bc6\u7801\u540e\uff0c\u4e3a\u4ec0\u4e48\u9a8c\u8bc1\u65f6\u8f93\u5165\u7684\u5bc6\u7801\u4f3c\u4e4e\u4e0d\u5339\u914d\uff0c\u4f46\u4ecd\u7136\u6210\u529f\uff1f<\/h1>\n<p>\u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u90fd\u6253\u5f00\u8fd9\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u4f7f\u7528 `password_hash()` \u6563\u5217\u5bc6\u7801\u540e\uff0c\u4e3a\u4ec0\u4e48\u9a8c\u8bc1\u65f6\u8f93\u5165\u7684\u5bc6\u7801\u4f3c\u4e4e\u4e0d\u5339\u914d\uff0c\u4f46\u4ecd\u7136\u6210\u529f\uff1f\u300b<\/span>\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\uff0c\u5b66\u4e0b\u53bb\u5427\uff01\u672c\u6587\u4e3b\u8981\u4f1a\u7ed9\u5927\u5bb6\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5927\u5bb6\u5bf9\u672c\u6587\u6709\u597d\u7684\u5efa\u8bae\u6216\u8005\u770b\u5230\u6709\u4e0d\u8db3\u4e4b\u5904\uff0c\u975e\u5e38\u6b22\u8fce\u5927\u5bb6\u79ef\u6781\u63d0\u51fa\uff01\u5728\u540e\u7eed\u6587\u7ae0\u6211\u4f1a\u7ee7\u7eed\u66f4\u65b0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u5185\u5bb9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1730025768671e19282e1e2.jpg\" class=\"aligncenter\" title=\"\u4f7f\u7528 `password_hash()` \u6563\u5217\u5bc6\u7801\u540e\uff0c\u4e3a\u4ec0\u4e48\u9a8c\u8bc1\u65f6\u8f93\u5165\u7684\u5bc6\u7801\u4f3c\u4e4e\u4e0d\u5339\u914d\uff0c\u4f46\u4ecd\u7136\u6210\u529f\uff1f\u63d2\u56fe\" alt=\"\u4f7f\u7528 `password_hash()` \u6563\u5217\u5bc6\u7801\u540e\uff0c\u4e3a\u4ec0\u4e48\u9a8c\u8bc1\u65f6\u8f93\u5165\u7684\u5bc6\u7801\u4f3c\u4e4e\u4e0d\u5339\u914d\uff0c\u4f46\u4ecd\u7136\u6210\u529f\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>password_hash() \u5bc6\u7801\u6563\u5217\u7684\u53ef\u9760\u6027<\/strong><\/p>\n<p>\u8bb8\u591a\u5f00\u53d1\u4eba\u5458\u53ef\u80fd\u4f1a\u9047\u5230\u8fd9\u6837\u7684\u60c5\u51b5\uff1a\u7528\u6237\u8f93\u5165\u7684\u5bc6\u7801\u4f3c\u4e4e\u4e0e\u54c8\u5e0c\u540e\u7684\u5b58\u50a8\u5bc6\u7801\u4e0d\u5339\u914d\uff0c\u4f46\u5b9e\u9645\u60c5\u51b5\u5e76\u975e\u5982\u6b64\u3002\u9488\u5bf9\u5bc6\u7801\u54c8\u5e0c\u51fd\u6570 password_hash() \u7684\u4f7f\u7528\u63d0\u51fa\u4e86\u4e00\u4e2a\u95ee\u9898\u3002<\/p>\n<p><strong>\u95ee\u9898\u5185\u5bb9<\/strong><\/p>\n<p>\u5f00\u53d1\u4eba\u5458\u5c06\u7528\u6237\u8f93\u5165\u7684\u5bc6\u7801\u4f7f\u7528 password_hash() \u51fd\u6570\u8fdb\u884c\u54c8\u5e0c\u5904\u7406\uff0c\u7136\u540e\u5c06\u5176\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\u3002\u7136\u800c\uff0c\u5728\u9a8c\u8bc1\u7528\u6237\u51ed\u636e\u65f6\uff0c\u8f93\u5165\u7684\u5bc6\u7801\u4f3c\u4e4e\u4e0e\u5b58\u50a8\u7684\u54c8\u5e0c\u5bc6\u7801\u4e0d\u540c\uff0c\u4f46\u9a8c\u8bc1\u4ecd\u7136\u6210\u529f\u3002<\/p>\n<p><strong>\u95ee\u9898\u89e3\u7b54<\/strong><\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cpassword_hash() \u4f7f\u7528 bcrypt \u7b97\u6cd5\u751f\u6210\u5bc6\u7801\u6563\u5217\uff0c\u8be5\u7b97\u6cd5\u4ee5\u5176\u7a33\u5065\u6027\u548c\u5b89\u5168\u6027\u800c\u95fb\u540d\u3002\u6284\u5f55\u7528\u6237\u8f93\u5165\u7684\u4ee3\u7801\u6267\u884c\u540e\uff1a<\/p>\n<pre>    public function hashPassword(string $password)\n    {\n        return password_hash($password, PASSWORD_DEFAULT);\n    }<\/pre>\n<p>\u5176\u4e2d\uff1a<br \/>password_default\u8868\u793a\u4f7f\u7528 bcrypt \u7b97\u6cd5\u3002<\/p>\n<p>bcrypt \u7b97\u6cd5\u76f8\u5bf9\u8f83\u6162\uff0c\u56e0\u6b64\u5f88\u96be\u4f7f\u7528\u66b4\u529b\u7834\u89e3\u6216\u5f69\u8679\u8868\u653b\u51fb\u6765\u8fd8\u539f\u539f\u59cb\u5bc6\u7801\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u4f7f\u7528 password_hash() \u5b58\u50a8\u7684\u54c8\u5e0c\u5bc6\u7801\u88ab\u8ba4\u4e3a\u662f\u53ef\u9760\u7684\u3002<\/p>\n<p>\u4e0e\u54c8\u5e0c\u7b97\u6cd5\u65e0\u5173\uff0c\u6240\u63cf\u8ff0\u7684\u201c\u660e\u660e\u8f93\u5165\u7684\u5bc6\u7801\u4e0d\u6b63\u786e\uff0c\u4f46\u8fd8\u662f\u901a\u8fc7\u4e86\u201d\u7684\u60c5\u51b5\u53ef\u80fd\u53e6\u6709\u539f\u56e0\u3002\u7531\u4e8e\u4ee3\u7801\u4e2d\u6ca1\u6709\u5305\u542b\u4e1a\u52a1\u903b\u8f91\u6765\u9a8c\u8bc1\u5bc6\u7801\u5339\u914d\u6027\uff0c\u56e0\u6b64\u65e0\u6cd5\u786e\u5b9a\u6b64\u95ee\u9898\u7684\u6839\u6e90\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u4f7f\u7528 `password_hash()` \u6563\u5217\u5bc6\u7801\u540e\uff0c\u4e3a\u4ec0\u4e48\u9a8c\u8bc1\u65f6\u8f93\u5165\u7684\u5bc6\u7801\u4f3c\u4e4e\u4e0d\u5339\u914d\uff0c\u4f46\u4ecd\u7136\u6210\u529f\uff1f\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 `password_hash()` \u6563\u5217\u5bc6\u7801\u540e\uff0c\u4e3a\u4ec0\u4e48\u9a8c\u8bc1\u65f6\u8f93\u5165\u7684\u5bc6\u7801\u4f3c\u4e4e\u4e0d\u5339\u914d\uff0c\u4f46\u4ecd\u7136\u6210\u529f\uff1f \u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u90fd\u6253\u5f00\u8fd9\u7bc7\u300a\u4f7f\u7528 `password_hash()` \u6563\u5217\u5bc6\u7801\u540e\uff0c\u4e3a\u4ec0\u4e48\u9a8c\u8bc1\u65f6\u8f93\u5165\u7684\u5bc6\u7801\u4f3c\u4e4e\u4e0d\u5339\u914d\uff0c\u4f46\u4ecd\u7136\u6210\u529f\uff1f\u300b\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\uff0c\u5b66\u4e0b\u53bb\u5427\uff01\u672c\u6587\u4e3b\u8981\u4f1a\u7ed9\u5927\u5bb6\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5927\u5bb6\u5bf9\u672c\u6587\u6709\u597d\u7684\u5efa\u8bae\u6216\u8005\u770b\u5230\u6709\u4e0d\u8db3\u4e4b\u5904\uff0c\u975e\u5e38\u6b22\u8fce\u5927\u5bb6\u79ef\u6781\u63d0\u51fa\uff01\u5728\u540e\u7eed\u6587\u7ae0\u6211\u4f1a\u7ee7\u7eed\u66f4\u65b0\u6587\u7ae0\u76f8\u5173\u7684\u5185\u5bb9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u6709\u6240\u5e2e\u52a9\uff01 password_hash() \u5bc6\u7801\u6563\u5217\u7684\u53ef\u9760\u6027 \u8bb8\u591a\u5f00\u53d1\u4eba\u5458\u53ef\u80fd\u4f1a\u9047\u5230\u8fd9\u6837\u7684\u60c5\u51b5\uff1a\u7528\u6237\u8f93\u5165\u7684\u5bc6\u7801\u4f3c\u4e4e\u4e0e\u54c8\u5e0c\u540e\u7684\u5b58\u50a8\u5bc6\u7801\u4e0d\u5339\u914d\uff0c\u4f46\u5b9e\u9645\u60c5\u51b5\u5e76\u975e\u5982\u6b64\u3002\u9488\u5bf9\u5bc6\u7801\u54c8\u5e0c\u51fd\u6570 password_hash() \u7684\u4f7f\u7528\u63d0\u51fa\u4e86\u4e00\u4e2a\u95ee\u9898\u3002 \u95ee\u9898\u5185\u5bb9 \u5f00\u53d1\u4eba\u5458\u5c06\u7528\u6237\u8f93\u5165\u7684\u5bc6\u7801\u4f7f\u7528 password_hash() \u51fd\u6570\u8fdb\u884c\u54c8\u5e0c\u5904\u7406\uff0c\u7136\u540e\u5c06\u5176\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\u3002\u7136\u800c\uff0c\u5728\u9a8c\u8bc1\u7528\u6237\u51ed\u636e\u65f6\uff0c\u8f93\u5165\u7684\u5bc6\u7801\u4f3c\u4e4e\u4e0e\u5b58\u50a8\u7684\u54c8\u5e0c\u5bc6\u7801\u4e0d\u540c\uff0c\u4f46\u9a8c\u8bc1\u4ecd\u7136\u6210\u529f\u3002 \u95ee\u9898\u89e3\u7b54 \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cpassword_hash() \u4f7f\u7528 bcrypt \u7b97\u6cd5\u751f\u6210\u5bc6\u7801\u6563\u5217\uff0c\u8be5\u7b97\u6cd5\u4ee5\u5176\u7a33\u5065\u6027\u548c\u5b89\u5168\u6027\u800c\u95fb\u540d\u3002\u6284\u5f55\u7528\u6237\u8f93\u5165\u7684\u4ee3\u7801\u6267\u884c\u540e\uff1a public function hashPassword(string $password) { return password_hash($password, PASSWORD_DEFAULT); } \u5176\u4e2d\uff1apassword_default\u8868\u793a\u4f7f\u7528 bcrypt \u7b97\u6cd5\u3002 bcrypt \u7b97\u6cd5\u76f8\u5bf9\u8f83\u6162\uff0c\u56e0\u6b64\u5f88\u96be\u4f7f\u7528\u66b4\u529b\u7834\u89e3\u6216\u5f69\u8679\u8868\u653b\u51fb\u6765\u8fd8\u539f\u539f\u59cb\u5bc6\u7801\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u4f7f\u7528 password_hash() \u5b58\u50a8\u7684\u54c8\u5e0c\u5bc6\u7801\u88ab\u8ba4\u4e3a\u662f\u53ef\u9760\u7684\u3002 \u4e0e\u54c8\u5e0c\u7b97\u6cd5\u65e0\u5173\uff0c\u6240\u63cf\u8ff0\u7684\u201c\u660e\u660e\u8f93\u5165\u7684\u5bc6\u7801\u4e0d\u6b63\u786e\uff0c\u4f46\u8fd8\u662f\u901a\u8fc7\u4e86\u201d\u7684\u60c5\u51b5\u53ef\u80fd\u53e6\u6709\u539f\u56e0\u3002\u7531\u4e8e\u4ee3\u7801\u4e2d\u6ca1\u6709\u5305\u542b\u4e1a\u52a1\u903b\u8f91\u6765\u9a8c\u8bc1\u5bc6\u7801\u5339\u914d\u6027\uff0c\u56e0\u6b64\u65e0\u6cd5\u786e\u5b9a\u6b64\u95ee\u9898\u7684\u6839\u6e90\u3002 \u4eca\u5929\u5173\u4e8e\u300a\u4f7f\u7528 `password_hash()` \u6563\u5217\u5bc6\u7801\u540e\uff0c\u4e3a\u4ec0\u4e48\u9a8c\u8bc1\u65f6\u8f93\u5165\u7684\u5bc6\u7801\u4f3c\u4e4e\u4e0d\u5339\u914d\uff0c\u4f46\u4ecd\u7136\u6210\u529f\uff1f\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/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-48414","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48414","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=48414"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48414\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}