{"id":260,"date":"2018-03-15T16:38:32","date_gmt":"2018-03-15T16:38:32","guid":{"rendered":"https:\/\/www.haoyuan.info\/?p=260"},"modified":"2018-03-15T16:41:39","modified_gmt":"2018-03-15T16:41:39","slug":"%e7%94%a8node-js%e5%ae%9e%e7%8e%b0%e9%aa%8c%e8%af%81hustoj%e5%af%86%e7%a0%81%e6%a8%a1%e5%9d%97","status":"publish","type":"post","link":"https:\/\/haoyuan.info\/?p=260","title":{"rendered":"\u7528Node.js\u5b9e\u73b0\u9a8c\u8bc1HUSTOJ\u5bc6\u7801\u6a21\u5757"},"content":{"rendered":"<p>\u7531\u4e8eHUSTOJ\u4f7f\u7528binary sha1\u4ee5\u53caBASE64\u52a0\u76d0\u8fdb\u884c\u52a0\u5bc6\uff0c\u6211\u66fe\u7ecf\u5c1d\u8bd5\u7528crypto\u5728Node.js\u4e0a\u5b9e\u73b0\u529f\u80fd\u4e0e\u4e4b\u76f8\u540c\u7684\u6a21\u5757\u3002\u7136\u800c\u6309\u7167API \u8bf4\u660e\u64cd\u4f5c\u5e76\u4e0d\u80fd\u6210\u529f\u751f\u6210\u5bf9\u5e94\u7684\u5185\u5bb9\u3002\u7ecf\u8fc7\u5bf9Buffer\u8f6c\u7801\u5bc6\u6587\u53d1\u73b0\uff0c\u5728\u5bf9BASE64\u5bc6\u6587\u8fdb\u884c\u89e3\u5bc6\u65f6\uff0c\u5e94\u4f7f\u7528ASCII\u7f16\u7801\u8fdb\u884c\u89e3\u5bc6\uff0c\u800c\u5728\u5bf9\u660e\u6587\u52a0\u5bc6\u65f6\uff0c\u5219\u5e94\u8be5\u7528UTF-8\u8fdb\u884c\u52a0\u5bc6\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u5b9e\u73b0\u5982\u4e0b:<\/p>\n<p>[code lang=javascript]<br \/>\nconst crypto = require(&quot;crypto&quot;);<br \/>\nconst checkPassword = (originalPassword, inputPassword, newpassword) =&gt; {<br \/>\n    const convertedOriginalPasswordAscii = new Buffer(originalPassword, &quot;base64&quot;).toString(&quot;ascii&quot;);<br \/>\n    const convertedOriginalPassword = new Buffer(originalPassword, &quot;base64&quot;).toString();<br \/>\n    const salt = convertedOriginalPasswordAscii.substring(20);<br \/>\n    const SHA1Password = crypto.createHash(&quot;sha1&quot;)<br \/>\n        .update(crypto.createHash(&quot;md5&quot;)<br \/>\n            .update(inputPassword)<br \/>\n            .digest(&quot;hex&quot;) + salt)<br \/>\n        .digest() + salt;<br \/>\n    return SHA1Password === convertedOriginalPassword || newpassword === inputPassword;<br \/>\n};<\/p>\n<p>[\/code]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7531\u4e8eHUSTOJ\u4f7f\u7528binary sha1\u4ee5\u53caBASE64\u52a0\u76d0\u8fdb\u884c\u52a0\u5bc6\uff0c\u6211\u66fe\u7ecf\u5c1d\u8bd5\u7528crypto\u5728Node.j [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[17,8,32],"class_list":["post-260","post","type-post","status-publish","format-standard","hentry","category-1","tag-hustoj","tag-javascript","tag-node-js"],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8UC2c-4c","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/260","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=260"}],"version-history":[{"count":2,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/260\/revisions"}],"predecessor-version":[{"id":262,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/260\/revisions\/262"}],"wp:attachment":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=260"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}