Loading

soarli

使用js实现输入密码才能打开网页
function password() { var testV = 1; var pass1 = prompt('...
扫描右侧二维码阅读全文
27
2020/02

使用js实现输入密码才能打开网页

function password() {
var testV = 1;
var pass1 = prompt('Please input the password!','');
while (testV < 3) {
if (!pass1)
history.go(-1);
if (pass1 == "baizhuadmin") {
break;
}
testV+=1;
var pass1 =
prompt('Password error!');
}
if (pass1!="password" & testV ==3)
history.go(-1);
return " ";
}
document.write(password());

可能有人会疑虑,密码就在代码中,如果别人查看一下源码就知道密码了,
嗯哪,确实存在这个问题,虽然上面代码中做了些防护,如果密码输不对的话,就返回上一页,但只要在浏览器中关掉js功能就可以打开网页查看js源码,
那么如何解决呢?当然有办法,使用js密码加密混淆啊,出大招:Jshaman(http://www.jshaman.com/),可以在线加密js代码,
就把上面的代码,用jshaman加密一下,加密后代码如下:

var _0x36e0=['UGxlYXNlIGlucHV0IHRoZSBwYXNzd29yZCE\x3d','YmFpemh1YWRtaW4\x3d','UGFzc3dvcmQgZXJyb3Ih','cGFzc3dvcmQ\x3d','d3JpdGU\x3d'];(function(_0x14ba0c,_0x4281cd){var _0x76aed0=function(_0x357e52){while(--_0x357e52){_0x14ba0c['\x70\x75\x73\x68'](_0x14ba0c['\x73\x68\x69\x66\x74']());}};_0x76aed0(++_0x4281cd);}(_0x36e0,0x18b));var _0x036e=function(_0x5bd244,_0x19acdd){_0x5bd244=_0x5bd244-0x0;var _0x18950a=_0x36e0[_0x5bd244];if(_0x036e['\x69\x6e\x69\x74\x69\x61\x6c\x69\x7a\x65\x64']===undefined){(function(){var _0x35e27a=Function('\x72\x65\x74\x75\x72\x6e\x20\x28\x66\x75\x6e\x63\x74\x69\x6f\x6e\x20\x28\x29\x20'+'\x7b\x7d\x2e\x63\x6f\x6e\x73\x74\x72\x75\x63\x74\x6f\x72\x28\x22\x72\x65\x74\x75\x72\x6e\x20\x74\x68\x69\x73\x22\x29\x28\x29'+'\x29\x3b');var _0x25a917=_0x35e27a();var _0xbb5637='\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x2b\x2f\x3d';_0x25a917['\x61\x74\x6f\x62']||(_0x25a917['\x61\x74\x6f\x62']=function(_0x3f22c7){var _0x2c1aa8=String(_0x3f22c7)['\x72\x65\x70\x6c\x61\x63\x65'](/=+$/,'');for(var _0x4ab004=0x0,_0x31c921,_0x565a4b,_0x4b19d0=0x0,_0x38d053='';_0x565a4b=_0x2c1aa8['\x63\x68\x61\x72\x41\x74'](_0x4b19d0++);~_0x565a4b&&(_0x31c921=_0x4ab004%0x4?_0x31c921*0x40+_0x565a4b:_0x565a4b,_0x4ab004++%0x4)?_0x38d053+=String['\x66\x72\x6f\x6d\x43\x68\x61\x72\x43\x6f\x64\x65'](0xff&_0x31c921>>(-0x2*_0x4ab004&0x6)):0x0){_0x565a4b=_0xbb5637['\x69\x6e\x64\x65\x78\x4f\x66'](_0x565a4b);}return _0x38d053;});}());_0x036e['\x62\x61\x73\x65\x36\x34\x44\x65\x63\x6f\x64\x65\x55\x6e\x69\x63\x6f\x64\x65']=function(_0x1e7670){var _0x15209a=atob(_0x1e7670);var _0xfc80a=[];for(var _0xec3236=0x0,_0x5a7d9a=_0x15209a['\x6c\x65\x6e\x67\x74\x68'];_0xec3236<_0x5a7d9a;_0xec3236++){_0xfc80a+='\x25'+('\x30\x30'+_0x15209a['\x63\x68\x61\x72\x43\x6f\x64\x65\x41\x74'](_0xec3236)['\x74\x6f\x53\x74\x72\x69\x6e\x67'](0x10))['\x73\x6c\x69\x63\x65'](-0x2);}return decodeURIComponent(_0xfc80a);};_0x036e['\x64\x61\x74\x61']={};_0x036e['\x69\x6e\x69\x74\x69\x61\x6c\x69\x7a\x65\x64']=!![];}if(_0x036e['\x64\x61\x74\x61'][_0x5bd244]===undefined){_0x18950a=_0x036e['\x62\x61\x73\x65\x36\x34\x44\x65\x63\x6f\x64\x65\x55\x6e\x69\x63\x6f\x64\x65'](_0x18950a);_0x036e['\x64\x61\x74\x61'][_0x5bd244]=_0x18950a;}else{_0x18950a=_0x036e['\x64\x61\x74\x61'][_0x5bd244];}return _0x18950a;};function password(){var _0x30a940=0x1;var _0x5689e0=prompt(_0x036e('0x0'),'');while(_0x30a940<0x3){if(!_0x5689e0)history['go'](-0x1);if(_0x5689e0==_0x036e('0x1')){break;}_0x30a940+=0x1;var _0x5689e0=prompt(_0x036e('0x2'));}if(_0x5689e0!=_0x036e('0x3')&_0x30a940==0x3)history['go'](-0x1);return'\x20';}document[_0x036e('0x4')](password());

好了,这样密码也不见了。
js实现密码保护的网页,就是这么简单。

上面的代码在html文件中,放在script标签里就可以了。

原文地址:https://blog.csdn.net/weixin_34397291/article/details/91694971

最后修改:2020 年 04 月 01 日 10 : 40 PM

发表评论