<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 登录 + 记住密码 + 密码加密解密的更多相关文章

  1. java关于密码的加密解密

    密码的加密方法有多种,常见的为Aes.Md5 Aes加密,可逆. 其中,Md5加密是采用了散列算法,也就是哈希算法,可以进行多次散列加密.Md5加密是不可逆的,无法解密. MD5是不可逆的单向加密方式 ...

  2. 使用springboot完成密码的加密解密

    现今对于大多数公司来说,信息安全工作尤为重要,就像京东,阿里巴巴这样的大公司来说,信息安全是最为重要的一个话题,举个简单的例子: 就像这样的密码公开化,很容易造成一定的信息的泄露.所以今天我们要讲的就 ...

  3. Jquery 实现 “下次自动登录” 记住用户名密码功能

    转载自:http://blog.csdn.net/aspnet_lyc/article/details/12030039?utm_source=tuicool&utm_medium=refer ...

  4. SharedPreferences实现自动登录记住用户名密码

    最近Android项目需要一个自动登录功能,完成之后,特总结一下,此功能依靠SharedPreferences进行实现.   SharedPreferences简介 SharedPreferences ...

  5. springMVC web项目 对访问数据库的用户名密码进行加密解密

    在使用springMVC开发web项目中,数据库的用户名,密码一般都是配置在.properties文件中 然后在通过.xml配置文件引入.properties的变量,例如 在config.proper ...

  6. django删除表重建&修改用户密码&base64加密解密字符串&ps aux参数说明&各种Error例子

    1.django的queryset不支持负索引 AssertionError: Negative indexing is not supported. 2.django向前端JavaScript传递列 ...

  7. 16: vue + crypto-js + python前后端加密解密

    1.1 vue中使用crypto-js进行AES加密解密    参考博客:https://www.cnblogs.com/qixidi/p/10137935.html 1.初始化vue项目 vue i ...

  8. 移位密码(加密+解密)C++实现

    移位密码 加密C=Ek(m)=m+k mod 26 解密m=Dk(m)=c-k mod 26 密钥空间|k|=26=|c|=|m| #include<iostream> #include& ...

  9. [原创]K8Cscan4.0之Base64/HEX密码批量加密解密插件以及源码

    前言 今天抽空更新了Cscan,新增对C#编译的EXE动态调用,新增对PowerShell脚本动态调用(无论是否安装PowerShell) 增加一个字符串列表str.txt,用于存放任意字符串,比如帐 ...

随机推荐

  1. element-ui el-upload http-request自定义上传方法

    html <el-form-item class="upload-bg register-bg" prop="ad_url"> <div cl ...

  2. Spring Boot AOP Demo

    什么是AOP? AOP面向切面,切面将那些与业务无关,却被业务模块共同调用的逻辑提取并封装起来,减少了系统中的重复代码,降低了模块间的耦合度,同时提高了系统的可维护性. 实现策略JAVA SE动态代理 ...

  3. 树莓派-Ubuntu Mate开启远程桌面xrdp服务

    树莓派3B+安装Ubuntu Mate后,开启远程桌面xrdp服务可以使用KRDC或mstsc远程登录访问,感觉比vnc要快一些: $ sudo apt install xrdp 安装后重启xrdp服 ...

  4. rocksdb wiki文档阅读笔记

    由于是英文文档,不做笔记过一阵就忘了,现在把关键点记录到这,开发的时候使用. 具体wiki地址:https://github.com/facebook/rocksdb/wiki 1)Column Fa ...

  5. Python 内置函数 -- zip(), sorted(), filter()和map()

    内置函数1. zip() 打包(木桶效应)描述: zip() 函数用于将可迭代的对象作为参数, 将对象中对应的元素打包成一个个元组, 然后返回由这些元组组成的列表语法: zip([iterable, ...

  6. uni-app 使用本地打包配置安卓原生插件

    在使用 uni-app 开发的时候,遇到了一个很棘手的问题.即获取设备参数的时候 uni-app 并没有相关方法,而安卓开发是可以做到的,因为接的是三方推广,所以功能必须实现,所以求助了安卓的大佬帮我 ...

  7. python3速查参考- python基础 4 -> 元组 + 字典 + 字符串 的学习

    元组 元组:特点就是内容不可变,算只读的列表,可以被查询,不能被修改 a = 2, print(a) print(type(a)) b = ('a','b','c') print(b[1]) 运行结果 ...

  8. 3.React中的setstate的几个现象

    转载segfault 上面的一篇文章,https://segmentfault.com/a/1190000014498196 1.在同一个方法中多次setState是会被合并的,并且对相同属性的设置只 ...

  9. 无监督异常检测之卷积AE和卷积VAE

    尝试用卷积AE和卷积VAE做无监督检测,思路如下: 1.先用正常样本训练AE或VAE 2.输入测试集给AE或VAE,获得重构的测试集数据. 3.计算重构的数据和原始数据的误差,如果误差大于某一个阈值, ...

  10. 【计算机视觉】time of flight (TOF)

    目录(?)[-] 11 TOF初探 12 TOF研究机构 13 TOF之应用领域 14 TOF相机特点 2 深度相机比较 1 MESA系列介绍 2 PMD Tec系列 3 NATAL 4 primeS ...