澳门皇家赌场在线cookie记住密码,js中动用cookie达成记住密码作用

cookie是网址设计者放置在客户端(浏览器)的小文本文件,cookie不仅能落实保存密码作用,还足以由此cookie保存近日浏览记录扩大用户体验。

JavaScript中什么运用cookie达成记住密码成效及cookie相关函数介绍,cookie记住密码

cookie是网址设计者放置在客户端(浏览器)的小文本文件,cookie不仅可以够落到实处保存密码效率,仍可以透过cookie保存如今浏览记录扩张用户体验。

在登入分界面加多记住密码作用,作者首先想到的是在java后新北调用cookie存放账号密码,大约如下:

HttpServletRequest request 
HttpServletResponse response
Cookie username = new Cookie("username ","cookievalue");
Cookie password = new Cookie("password ","cookievalue");
response.addCookie(username );
response.addCookie(password );

然而为安全起见,大家在后台获取的密码繁多是在js中经过MD5加密后的密文,如果将密文放到cookie中,在js中获取到也平昔不效益;

接下来考虑在js中存取cookie,代码如下:

//设置cookie
var passKey = '4c05c54d952b11e691d76c0b843ea7f9';
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + encrypt(escape(cvalue), passKey) + "; " + expires;
}
//获取cookie
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) != -1){
var cnameValue = unescape(c.substring(name.length, c.length));
return decrypt(cnameValue, passKey);
} 
}
return "";
}
//清除cookie 
function clearCookie(cname) { 
setCookie(cname, "", -1); 
}

setCookie(cname, cvalue,
exdays)四个参数分别是存放在的cookie名字、cookie值、cookie有效天数

鉴于cookie中不能够包涵等号、空格、分号等特殊字符,笔者在设置cookie时采纳escape()
函数对字符串进行编码,获取cookie时行使unescape()函数解码。可是escape()函数不会对
ASCII
字母和数字实行编码,所以存放到cookie中的账号、密码是以公开存放的,不安全。于是上网找了三个对字符串加密解密算法,该算法供给传多个参数,一个亟需加密的字符串,两个自定义加密密钥passKey。设置cookie时采用encrypt(value,
passkey)加密,读取cookie时使用decrypt(value,
passKey)解密,该算法附在本文最终。

存取cookie方法的调用:

1、定义checkbox

<input type="checkbox" id="rememberMe" checked="checked"/>记住密码

2、判别帐号密码输入准确后调用

if($('#rememberMe').is(':checked')){
setCookie('customername', $('#username').val().trim(), 7)
setCookie('customerpass', $('#password').val().trim(), 7)
}

3、进入登入分界面后,决断cookie中是不是有帐号密码,如若有就机关填写

$(function(){
//获取cookie
var cusername = getCookie('customername');
var cpassword = getCookie('customerpass');
if(cusername != "" && cpassword != ""){
$("#username").val(cusername);
$("#password").val(cpassword);
}
}

末段附上字符串加密解密算法

eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('A G(a,b){x(b==v||b.7<=0){D.y("z R P O");t v}6 c="";s(6 i=0;i<b.7;i++){c+=b.u(i).n()}6 d=m.r(c.7/5);6 e=l(c.9(d)+c.9(d*2)+c.9(d*3)+c.9(d*4)+c.9(d*5));6 f=m.M(b.7/2);6 g=m.B(2,C)-1;x(e<2){D.y("L K J z");t v}6 h=m.F(m.H()*N)%I;c+=h;w(c.7>q){c=(l(c.o(0,q))+l(c.o(q,c.7))).n()}c=(e*c+f)%g;6 j="";6 k="";s(6 i=0;i<a.7;i++){j=l(a.u(i)^m.r((c/g)*E));x(j<p){k+="0"+j.n(p)}Q k+=j.n(p);c=(e*c+f)%g}h=h.n(p);w(h.7<8)h="0"+h;k+=h;t k}A S(a,b){6 c="";s(6 i=0;i<b.7;i++){c+=b.u(i).n()}6 d=m.r(c.7/5);6 e=l(c.9(d)+c.9(d*2)+c.9(d*3)+c.9(d*4)+c.9(d*5));6 f=m.F(b.7/2);6 g=m.B(2,C)-1;6 h=l(a.o(a.7-8,a.7),p);a=a.o(0,a.7-8);c+=h;w(c.7>q){c=(l(c.o(0,q))+l(c.o(q,c.7))).n()}c=(e*c+f)%g;6 j="";6 k="";s(6 i=0;i<a.7;i+=2){j=l(l(a.o(i,i+2),p)^m.r((c/g)*E));k+=T.U(j);c=(e*c+f)%g}t k}',57,57,'||||||var|length||charAt||||||||||||parseInt|Math|toString|substring|16|10|floor|for|return|charCodeAt|null|while|if|log|key|function|pow|31|console|255|round|encrypt|random|100000000|the|change|plesae|ceil|1000000000|empty|be|else|cannot|decrypt|String|fromCharCode'.split('|'),0,{}))

PS:上边看下js操作cookie的相关函数

//设置cookie函数,三个参数,一个是cookie的名子,一个是值,一个是设置cookie保存时间,单位:天
function SetCookie(name,value,days){
 var days=arguments[2]?arguments[2]:30; //此 cookie 将被保存 30 天
 var exp=new Date(); //new Date("December 31, 9998");
 exp.setTime(exp.getTime() + days*86400000);
 document.cookie=name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
//取cookies函数
function getCookie(name){
 var arr=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
 if(arr!=null){
 return unescape(arr[2]);
 }
 return null;
}
//删除cookie函数
function delCookie(name){
 var exp = new Date();
 exp.setTime(exp.getTime() - 1);
 var cval=getCookie(name);
 if(cval!=null){
 document.cookie= name + "="+cval+";expires="+exp.toGMTString();
 }
}

以上所述是作者给我们介绍的JavaScript中怎么着利用cookie完毕记住密码成效及cookie相关函数介绍,希望对大家享有帮忙,如若我们有其余疑问请给作者留言,作者会及时回复大家的。在此也特别谢谢大家对帮客之家网址的帮忙!

cookie是网站设计者放置在客户端(浏览器)的小文本文件,…

 

在报到分界面增多记住密码作用,笔者先是想到的是在java后新竹调用cookie存放账号密码,差相当少如下:

js中选取cookie达成记住密码效用

在登入分界面增添记住密码作用,我首先想到的是在java后台南调用cookie存放账号密码,大约如下:

澳门皇家赌场在线 1

1 HttpServletRequest request  
2 HttpServletResponse response
3 Cookie username = new Cookie("username ","cookievalue");
4 Cookie password = new Cookie("password ","cookievalue");
5 response.addCookie(username );
6 response.addCookie(password );

澳门皇家赌场在线 2

但是为安全起见,大家在后台获取的密码好些个是在js中经过MD5加密后的密文,假使将密文放到cookie中,在js中拿走到也不曾效率;

接下来思虑在js中存取cookie,代码如下:

澳门皇家赌场在线 3

 1 //设置cookie
 2 var passKey = '4c05c54d952b11e691d76c0b843ea7f9';
 3 function setCookie(cname, cvalue, exdays) {
 4     var d = new Date();
 5     d.setTime(d.getTime() + (exdays*24*60*60*1000));
 6     var expires = "expires="+d.toUTCString();
 7     document.cookie = cname + "=" + encrypt(escape(cvalue), passKey) + "; " + expires;
 8 }
 9 //获取cookie
10 function getCookie(cname) {
11     var name = cname + "=";
12     var ca = document.cookie.split(';');
13     for(var i=0; i<ca.length; i++) {
14         var c = ca[i];
15         while (c.charAt(0)==' ') c = c.substring(1);
16         if (c.indexOf(name) != -1){
17           var cnameValue = unescape(c.substring(name.length, c.length));
18           return decrypt(cnameValue, passKey);
19         } 
20     }
21     return "";
22 }
23 //清除cookie  
24 function clearCookie(cname) {  
25     setCookie(cname, "", -1);  
26 }

澳门皇家赌场在线 4

setCookie(cname, cvalue,
exdays)多少个参数分别是存放的cookie名字、cookie值、cookie有效天数

鉴于cookie中不可能包括等号、空格、分号等特殊字符,作者在安装cookie时使用escape()
函数对字符串实行编码,获取cookie时利用unescape()函数解码。然则escape()函数不会对
ASCII
字母和数字进行编码,所以存放到cookie中的账号、密码是以公开存放的,不安全。于是上网找了多少个对字符串加密解密算法,该算法须要传多个参数,八个亟需加密的字符串,三个自定义加密密钥passKey。设置cookie时选择encrypt(value,
passkey)加密,读取cookie时行使decrypt(value,
passKey)解密,该算法附在本文最终。

存取cookie方法的调用:

1、定义checkbox

<input type="checkbox" id="rememberMe" checked="checked"/>记住密码

 

2、推断帐号密码输入正确后调用

1 if($('#rememberMe').is(':checked')){
2             setCookie('customername', $('#username').val().trim(), 7)
3             setCookie('customerpass', $('#password').val().trim(), 7)
4           }

3、进入登陆分界面后,判定cookie中是或不是有帐号密码,若是有就机关填写

澳门皇家赌场在线 5

$(function(){

  //获取cookie
  var cusername = getCookie('customername');
  var cpassword = getCookie('customerpass');
  if(cusername != "" && cpassword != ""){
    $("#username").val(cusername);
    $("#password").val(cpassword);
  }
}

澳门皇家赌场在线 6

最后附上字符串加密解密算法

澳门皇家赌场在线 7

1 eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('A G(a,b){x(b==v||b.7<=0){D.y("z R P O");t v}6 c="";s(6 i=0;i<b.7;i++){c+=b.u(i).n()}6 d=m.r(c.7/5);6 e=l(c.9(d)+c.9(d*2)+c.9(d*3)+c.9(d*4)+c.9(d*5));6 f=m.M(b.7/2);6 g=m.B(2,C)-1;x(e<2){D.y("L K J z");t v}6 h=m.F(m.H()*N)%I;c+=h;w(c.7>q){c=(l(c.o(0,q))+l(c.o(q,c.7))).n()}c=(e*c+f)%g;6 j="";6 k="";s(6 i=0;i<a.7;i++){j=l(a.u(i)^m.r((c/g)*E));x(j<p){k+="0"+j.n(p)}Q k+=j.n(p);c=(e*c+f)%g}h=h.n(p);w(h.7<8)h="0"+h;k+=h;t k}A S(a,b){6 c="";s(6 i=0;i<b.7;i++){c+=b.u(i).n()}6 d=m.r(c.7/5);6 e=l(c.9(d)+c.9(d*2)+c.9(d*3)+c.9(d*4)+c.9(d*5));6 f=m.F(b.7/2);6 g=m.B(2,C)-1;6 h=l(a.o(a.7-8,a.7),p);a=a.o(0,a.7-8);c+=h;w(c.7>q){c=(l(c.o(0,q))+l(c.o(q,c.7))).n()}c=(e*c+f)%g;6 j="";6 k="";s(6 i=0;i<a.7;i+=2){j=l(l(a.o(i,i+2),p)^m.r((c/g)*E));k+=T.U(j);c=(e*c+f)%g}t k}',57,57,'||||||var|length||charAt||||||||||||parseInt|Math|toString|substring|16|10|floor|for|return|charCodeAt|null|while|if|log|key|function|pow|31|console|255|round|encrypt|random|100000000|the|change|plesae|ceil|1000000000|empty|be|else|cannot|decrypt|String|fromCharCode'.split('|'),0,{}))

澳门皇家赌场在线 8

 

-此小说为转载-转载至

HttpServletRequest request 
HttpServletResponse response
Cookie username = new Cookie("username ","cookievalue");
Cookie password = new Cookie("password ","cookievalue");
response.addCookie(username );
response.addCookie(password );

而是为平安起见,大家在后台获取的密码许多是在js中通过MD5加密后的密文,假设将密文放到cookie中,在js中得到到也尚无坚守;

接下来思量在js中存取cookie,代码如下:

//设置cookie
var passKey = '4c05c54d952b11e691d76c0b843ea7f9';
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + encrypt(escape(cvalue), passKey) + "; " + expires;
}
//获取cookie
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) != -1){
var cnameValue = unescape(c.substring(name.length, c.length));
return decrypt(cnameValue, passKey);
} 
}
return "";
}
//清除cookie 
function clearCookie(cname) { 
setCookie(cname, "", -1); 
}

set库克ie(cname, cvalue,
exdays)三个参数分别是存放的cookie名字、cookie值、cookie有效天数

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图