{"id":1543,"date":"2020-09-28T16:09:43","date_gmt":"2020-09-28T08:09:43","guid":{"rendered":"https:\/\/www.yusian.com\/blog\/?p=1543"},"modified":"2020-12-01T12:49:55","modified_gmt":"2020-12-01T04:49:55","slug":"%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e6%a0%a1%e9%aa%8c%e5%af%86%e7%a0%81%e5%bc%ba%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/project\/2020\/09\/28\/1609431543.html","title":{"rendered":"\u6b63\u5219\u8868\u8fbe\u5f0f\u6821\u9a8c\u5bc6\u7801\u5f3a\u5ea6"},"content":{"rendered":"<h2>\u9700\u6c42\u5206\u6790<\/h2>\n<ul>\n<li>\u5bc6\u7801\u5408\u6cd5\u5b57\u7b26\u5305\u62ec\uff1a\u6570\u5b57\u3001\u5b57\u6bcd\u5927\u5c0f\u5199\u3001\u6807\u70b9\u7b26\u53f7\uff1b<\/li>\n<li>\u5bc6\u7801\u5f3a\u5ea6\u4e00\u822c\u9700\u8981\u4ee5\u4e0a\u7c7b\u578b\u7684\u7ec4\u5408\u53ca\u957f\u5ea6\u8981\u6c42\uff1b<\/li>\n<\/ul>\n<h2>\u529f\u80fd\u5b9e\u73b0<\/h2>\n<ol>\n<li>\u5148\u5206\u522b\u5199\u51fa\u4ee5\u4e0a4\u79cd\u7ec4\u5408\u7684\u6b63\u5219\u8868\u8fbe\u5f0f<\/li>\n<\/ol>\n<pre><code class=\"language-javascript line-numbers\">let password = 'aBcdefg123!'\n\/\/ \u6570\u5b57\nlet reg1 = '\\\\d';\n\/\/ \u5b57\u6bcd\nlet reg21 = '[a-z]';\nlet reg22 = '[A-Z]';\n\/\/ \u7b26\u53f7\nlet reg3 = '[`\\\\-=\\\\[\\\\]\\\\\\\\;\\',.\\\/~!@#$%^&amp;*()_+{}|:\"&lt;&gt;?]';\n<\/code><\/pre>\n<ol start=\"2\">\n<li>\u68c0\u6d4b\u6574\u4e2a\u5bc6\u7801\u662f\u5426\u7b26\u5408\u4ee5\u4e0a\u7ec4\u5408\u5339\u914d\u8981\u6c42\u53ca\u957f\u5ea6\u8981\u6c426-20\u4f4d<\/li>\n<\/ol>\n<pre><code class=\"language-javascript line-numbers\">\/\/ \u6df7\u5408\u5339\u914d\nlet reg = new RegExp(`^(${reg1}|${reg21}|${reg22)|${reg3}){6,20}$`);\nlet ret = reg.test(password);\n<\/code><\/pre>\n<ol start=\"3\">\n<li>\u4f7f\u7528\u7ec4\u5408\u4e2d\u7684\u6b63\u5219\u5206\u522b\u5bf9\u5bc6\u7801\u8fdb\u884c\u6821\u9a8c\uff0c\u83b7\u53d6\u6ee1\u8db3\u7684\u7ec4\u5408\u6570\u6765\u6821\u9a8c\u5f3a\u5ea6<\/li>\n<\/ol>\n<pre><code class=\"language-javascript line-numbers\">\/\/ \u7b26\u5408\u89c4\u5219\u6570\nlet regs = [reg1, reg21, reg22, reg3];\nlet num = regs.reduce(function (sum, regStr, index, regs) {\n    let b = new RegExp(regStr).test(password);\n    return (b ? 1 : 0) + sum\n}, 0)\nif (ret &amp;&amp; num &gt; 2) {\n    console.log('\u5408\u6cd5,', num);\n} else {\n    console.log('\u4e0d\u5408\u6cd5,', num);\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u6c42\u5206\u6790 \u5bc6\u7801\u5408\u6cd5\u5b57\u7b26\u5305\u62ec\uff1a\u6570\u5b57\u3001\u5b57\u6bcd\u5927\u5c0f\u5199\u3001\u6807\u70b9\u7b26\u53f7\uff1b \u5bc6\u7801\u5f3a\u5ea6\u4e00\u822c\u9700\u8981\u4ee5\u4e0a\u7c7b\u578b\u7684\u7ec4\u5408\u53ca\u957f\u5ea6\u8981\u6c42\uff1b \u529f\u80fd\u5b9e\u73b0 \u5148\u5206\u522b\u5199\u51fa\u4ee5\u4e0a4\u79cd\u7ec4\u5408\u7684\u6b63\u5219\u8868\u8fbe\u5f0f let password = &#8216;aBcdefg123!&#8217; \/\/ \u6570\u5b57 let reg1 = &#8216;\\\\d&#8217;; \/\/ \u5b57\u6bcd let reg21 = &#8216;[a-z]&#8217;; let reg22 = &#8216;[A-Z]&#8217;; \/\/ \u7b26\u53f7 let reg3 = &#8216;[`\\\\-=\\\\[\\\\]\\\\\\\\;\\&#8217;,.\\\/~!@#$%^&amp;*()_+{}|:&#8221;&lt;&gt;?]&#8217;; \u68c0\u6d4b\u6574\u4e2a\u5bc6\u7801\u662f\u5426\u7b26\u5408\u4ee5\u4e0a\u7ec4\u5408\u5339\u914d\u8981\u6c42\u53ca\u957f\u5ea6\u8981\u6c426-20\u4f4d \/\/ \u6df7\u5408\u5339\u914d let reg = new RegExp(`^(${reg1}|${reg21}|${reg22)|${reg3}){6,20}$`); let ret = reg.test(password); \u4f7f\u7528\u7ec4\u5408\u4e2d\u7684\u6b63\u5219\u5206\u522b\u5bf9\u5bc6\u7801\u8fdb\u884c\u6821\u9a8c\uff0c\u83b7\u53d6\u6ee1\u8db3\u7684\u7ec4\u5408\u6570\u6765\u6821\u9a8c\u5f3a\u5ea6 \/\/ \u7b26\u5408\u89c4\u5219\u6570 let regs = [reg1, reg21, reg22, reg3]; let num [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,35,28,11],"tags":[53,238,237,239],"class_list":["post-1543","post","type-post","status-publish","format-standard","hentry","category-android","category-java","category-javascript","category-project","tag-javascript","tag-regexp","tag-237","tag-239"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/1543","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=1543"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/1543\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=1543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=1543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=1543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}