vue 登录 + 记住密码 + 密码加密解密
<template>
<el-form :model="ruleForm">
<h3 class="title">系统登录</h3>
<el-form-item prop="mobile">
<el-input type="text" v-model="ruleForm.mobile" auto-complete="off" placeholder="账号"></el-input>
</el-form-item>
<el-form-item prop="password">
<el-input type="password" v-model="ruleForm.password" auto-complete="off" placeholder="密码"></el-input>
</el-form-item>
<el-checkbox v-model="checked" checked>记住密码</el-checkbox>
<el-form-item>
<el-button type="primary" @click.native.prevent="handleSubmit">登录</el-button>
</el-form-item>
</el-form>
</template>
<script>
import { apis } from '../uitl/config'
import CryptoJS from 'crypto-js' //加密js
export default {
data() {
return {
ruleForm: {
mobile: '', //账号
password: '' //密码
},
checked: true //是否选中记住密码 true为选中
};
},
methods:{
//登录方法
handleSubmit() {
var that = this;
let loginParams = {
mobile: this.ruleForm.mobile, //获取账号
password: this.ruleForm.password //获取密码
};
//登录请求
that.$axios.post(`${api}/auth/login`,loginParams).then((res)=>{
if(res.data.errCode == 0){
console.log('登录成功')
if (that.checked == true) {
//传入账号,密码,保存天数
that.setCookie(that.ruleForm.mobile, that.ruleForm.password, 7);
} else {
//清空Cookie
that.clearCookie();
}
//跳转路由
that.$router.push({ path: '/index' });
}else{
console.log('登录失败')
}
})
},
//设置cookie方法
setCookie(mobile, password, days) {
var text = CryptoJS.AES.encrypt(password, 'secret key 123');//使用CryptoJS方法加密
var saveDays = new Date(); //获取时间
saveDays.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * days); //保存的天数
//字符串拼接存入cookie
window.document.cookie = "mobile" + "=" + mobile + ";path=/;saveDays=" + saveDays.toGMTString();
window.document.cookie = "password" + "=" + text + ";path=/;saveDays=" + saveDays.toGMTString();
},
//读取cookie
getCookie() {
if (document.cookie.length > 0) {
var arr = document.cookie.split('; '); //这里显示的格式需要切割一下自己可输出看下
for (var i = 0; i < arr.length; i++) {
var arr2 = arr[i].split('='); //再次切割
//这里会切割出以mobile为第0项的数组、以password为第0项的数组,判断查找相对应的值
if (arr2[0] == 'mobile') {
this.ruleForm.mobile = arr2[1]; //拿到账号
} else if (arr2[0] == 'password') {
//拿到拿到加密后的密码arr2[1]并解密
var bytes = CryptoJS.AES.decrypt(arr2[1].toString(), 'secret key 123');
var plaintext = bytes.toString(CryptoJS.enc.Utf8); //拿到解密后的密码(登录时输入的密码)
this.ruleForm.password = plaintext;
}
}
}
},
//清除cookie
clearCookie() {
this.setCookie("", "", 0); //账号密码置空,天数置0
}
}
}
</script>
需要装加密插件
pm install crypto-js
vue 登录 + 记住密码 + 密码加密解密的更多相关文章
- java关于密码的加密解密
密码的加密方法有多种,常见的为Aes.Md5 Aes加密,可逆. 其中,Md5加密是采用了散列算法,也就是哈希算法,可以进行多次散列加密.Md5加密是不可逆的,无法解密. MD5是不可逆的单向加密方式 ...
- 使用springboot完成密码的加密解密
现今对于大多数公司来说,信息安全工作尤为重要,就像京东,阿里巴巴这样的大公司来说,信息安全是最为重要的一个话题,举个简单的例子: 就像这样的密码公开化,很容易造成一定的信息的泄露.所以今天我们要讲的就 ...
- Jquery 实现 “下次自动登录” 记住用户名密码功能
转载自:http://blog.csdn.net/aspnet_lyc/article/details/12030039?utm_source=tuicool&utm_medium=refer ...
- SharedPreferences实现自动登录记住用户名密码
最近Android项目需要一个自动登录功能,完成之后,特总结一下,此功能依靠SharedPreferences进行实现. SharedPreferences简介 SharedPreferences ...
- springMVC web项目 对访问数据库的用户名密码进行加密解密
在使用springMVC开发web项目中,数据库的用户名,密码一般都是配置在.properties文件中 然后在通过.xml配置文件引入.properties的变量,例如 在config.proper ...
- django删除表重建&修改用户密码&base64加密解密字符串&ps aux参数说明&各种Error例子
1.django的queryset不支持负索引 AssertionError: Negative indexing is not supported. 2.django向前端JavaScript传递列 ...
- 16: vue + crypto-js + python前后端加密解密
1.1 vue中使用crypto-js进行AES加密解密 参考博客:https://www.cnblogs.com/qixidi/p/10137935.html 1.初始化vue项目 vue i ...
- 移位密码(加密+解密)C++实现
移位密码 加密C=Ek(m)=m+k mod 26 解密m=Dk(m)=c-k mod 26 密钥空间|k|=26=|c|=|m| #include<iostream> #include& ...
- [原创]K8Cscan4.0之Base64/HEX密码批量加密解密插件以及源码
前言 今天抽空更新了Cscan,新增对C#编译的EXE动态调用,新增对PowerShell脚本动态调用(无论是否安装PowerShell) 增加一个字符串列表str.txt,用于存放任意字符串,比如帐 ...
随机推荐
- Hibernate3核心API-Session接口
Session是应用程序与数据库之间交互操作的一个单线程对象,是 Hibernate 运作的中心,所有持久化对象必须在 session 的管理下才可以进行持久化操作.此对象的生命周期很短.Sessio ...
- asyncio模块实现单线程-多任务的异步协程
本篇介绍基于asyncio模块,实现单线程-多任务的异步协程 基本概念 协程函数 协程函数: 定义形式为 async def 的函数; aysnc 在Python3.5+版本新增了aysnc和awai ...
- 视图push和presentViewController注意点
presentViewController: - (void)publishClick{ NSLog(@"发布按钮被点击"); PublishViewController *pub ...
- redis单机版无法启动java程序解决
1.注释掉 bind 127.0.0.1 2.kill-9 杀死进行 3.redis-server + 配置文件进行重启,
- Django组件-admin
一. admin组件的使用 Django 提供了基于 web 的管理工具. Django 自动管理工具是 django.contrib 的一部分.你可以在项目的 settings.py 中的 INST ...
- 在vue中使用Normalize初始化样式
参考链接:https://www.jianshu.com/p/34533b45aac1
- 用elasticsearch分析中国大学省份分布
1.去教育部官网下载excel数据:http://www.moe.gov.cn/srcsite/A03/moe_634/201706/W020170616379651135432.xls 2.把xls ...
- 零零散散的python笔记
Python strip()方法 用于移除字符串头尾指定的字符(默认为空格或换行符)或字符序列. #!/usr/bin/python # -*- coding: UTF-8 -*- str = &qu ...
- 上传本地文件到SVN
前言:今天按照自己的记忆上传本地文件夹到SVN,出现了点问题,重温了简单操作. https://blog.csdn.net/qq_35150366/article/details/81129847 参 ...
- Linux 脚本
1.理解Linux Shell和基本Shell脚本语言的小贴士(一) http://blog.jobbole.com/63952/ ------伯乐在线