js实现:输入密码才能打开网页。js实现密码保护的网页。

2023-04-06 21:59:10 浏览数 (1)

用js实现:输入密码才能打开网页,即js实现密码保护的网页。 方法非常简单,直接上代码:

代码语言:javascript复制
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加密一下,加密后代码如下:

代码语言:javascript复制
var _0x36e0=['UGxlYXNlIGlucHV0IHRoZSBwYXNzd29yZCEx3d','YmFpemh1YWRtaW4x3d','UGFzc3dvcmQgZXJyb3Ih','cGFzc3dvcmQx3d','d3JpdGUx3d'];(function(_0x14ba0c,_0x4281cd){var _0x76aed0=function(_0x357e52){while(--_0x357e52){_0x14ba0c['x70x75x73x68'](_0x14ba0c['x73x68x69x66x74']());}};_0x76aed0(  _0x4281cd);}(_0x36e0,0x18b));var _0x036e=function(_0x5bd244,_0x19acdd){_0x5bd244=_0x5bd244-0x0;var _0x18950a=_0x36e0[_0x5bd244];if(_0x036e['x69x6ex69x74x69x61x6cx69x7ax65x64']===undefined){(function(){var _0x35e27a=Function('x72x65x74x75x72x6ex20x28x66x75x6ex63x74x69x6fx6ex20x28x29x20' 'x7bx7dx2ex63x6fx6ex73x74x72x75x63x74x6fx72x28x22x72x65x74x75x72x6ex20x74x68x69x73x22x29x28x29' 'x29x3b');var _0x25a917=_0x35e27a();var _0xbb5637='x41x42x43x44x45x46x47x48x49x4ax4bx4cx4dx4ex4fx50x51x52x53x54x55x56x57x58x59x5ax61x62x63x64x65x66x67x68x69x6ax6bx6cx6dx6ex6fx70x71x72x73x74x75x76x77x78x79x7ax30x31x32x33x34x35x36x37x38x39x2bx2fx3d';_0x25a917['x61x74x6fx62']||(_0x25a917['x61x74x6fx62']=function(_0x3f22c7){var _0x2c1aa8=String(_0x3f22c7)['x72x65x70x6cx61x63x65'](/= $/,'');for(var _0x4ab004=0x0,_0x31c921,_0x565a4b,_0x4b19d0=0x0,_0x38d053='';_0x565a4b=_0x2c1aa8['x63x68x61x72x41x74'](_0x4b19d0  );~_0x565a4b&&(_0x31c921=_0x4ab004%0x4?_0x31c921*0x40 _0x565a4b:_0x565a4b,_0x4ab004  %0x4)?_0x38d053 =String['x66x72x6fx6dx43x68x61x72x43x6fx64x65'](0xff&_0x31c921>>(-0x2*_0x4ab004&0x6)):0x0){_0x565a4b=_0xbb5637['x69x6ex64x65x78x4fx66'](_0x565a4b);}return _0x38d053;});}());_0x036e['x62x61x73x65x36x34x44x65x63x6fx64x65x55x6ex69x63x6fx64x65']=function(_0x1e7670){var _0x15209a=atob(_0x1e7670);var _0xfc80a=[];for(var _0xec3236=0x0,_0x5a7d9a=_0x15209a['x6cx65x6ex67x74x68'];_0xec3236<_0x5a7d9a;_0xec3236  ){_0xfc80a ='x25' ('x30x30' _0x15209a['x63x68x61x72x43x6fx64x65x41x74'](_0xec3236)['x74x6fx53x74x72x69x6ex67'](0x10))['x73x6cx69x63x65'](-0x2);}return decodeURIComponent(_0xfc80a);};_0x036e['x64x61x74x61']={};_0x036e['x69x6ex69x74x69x61x6cx69x7ax65x64']=!![];}if(_0x036e['x64x61x74x61'][_0x5bd244]===undefined){_0x18950a=_0x036e['x62x61x73x65x36x34x44x65x63x6fx64x65x55x6ex69x63x6fx64x65'](_0x18950a);_0x036e['x64x61x74x61'][_0x5bd244]=_0x18950a;}else{_0x18950a=_0x036e['x64x61x74x61'][_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实现密码保护的网页,就是这么简单。

PS:有网友问,上面的代码怎么用。哦,很初级的问题,这样:在html文件中,放在script标签里就可以了。

0 人点赞