<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="./md5.js"></script>
<script>
/*
md5 加密
管他怎么实现的 拿来用就行了
*/
var user = 'ycy';
var password = 'zzzzzz';
password = hex_md5(password)
console.log(password);
// 比对md5加密的结果
/*
md5 加密是无法解密的 ==> 只是扯犊子的
撞库 一一对比来解密的 枚举法 穷举法 暴力破解
所以用来加密比对来进行使用
密码复杂 大小姐不一样就可能撞不出来了
硬盘能恢复的数据
使用二次三次加密
多次加密就很难破解了
*/
let obj = {
name: "ycy",
age: '10',
gender: 'male'
}
// let str = ''
// for( let item in obj ){
// str += `${item}=${obj[item]};`
// }
// console.log(str)
// document.cookie = str;
function setCookie(obj, date) {
for (var item in obj) {
document.cookie = `${item}=${obj[item]};expires=${date.toUTCString()}`
}
}
var date = new Date();
date.setFullYear(2028)
setCookie(obj, date);
/*
对象不能使for of 遍历
使用for in 遍历
object 没有迭代器 所以不能使用for of 遍历
*/
// console.log( document.cookie )// 是一个字符串 所有的cookie的字符串
function getCookie() {
var arr = document.cookie.split('; ');
let obj = {}
for (let item of arr) {
var _arr = item.split('=');
obj[_arr[0]] = _arr[1]
}
return obj;
}
function getCookie1() {
//reduce 归并 一种迭代
return document.cookie.split('; ').reduce((val, item) => {
// console.log(item)
let arr = item.split('=');
val[arr[0]] = isNaN( arr[1] ) ? arr[1] : Number( arr[1] );
return val
}, {})
// {} 对象先被带入value中
}
let res = getCookie();
let res1 = getCookie1();
console.log(res, res1)
// console.log( isNaN(num) )
/*
判断是不是数字
1.isNaN 不严谨
2. 正则
3.typeof Number
*/
/*
cookie 需要设置过期时间
否则就是session
cookie是临时存储
cookie重新设置 就是重置过期时间了
*/
</script>
</body>
</html>
cookie的遍历 对象不能使用for of 遍历,因为内部没有迭代器
最新推荐文章于 2022-07-12 18:39:03 发布