<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. 网站title,meta,description如何设置,长度大小多少合适!

    转自:http://www.os1010.com/archives/1682 如 何 把 握 html 网 页 中 的 meta 标 签 对于高级的搜索引擎来说,html 的meta 标签并不是什么新 ...

  2. pm2 使用

    详见:https://www.cnblogs.com/chyingp/p/pm2-documentation.html

  3. Spring Cloud(3):配置服务(Config)

    Spring Cloud Config的目标是在在大量的微服务中,将服务配置信息和和服务的实际物理部署分离,且服务配置服务不应与服务实例一起部署.配置信息应该作为环境变量传递给正在启动的服务,或者在服 ...

  4. Java数组(3):创建测试数据

    有时我们需要使用数组批量创建测试数据,接下来通过以下4点来举例. (1) 使用Arrays.fill()填充数据 (2) 使用Random类中JDK1.8提供的新方法用来生成随机数 (3) 一个随机数 ...

  5. 上传NUnit的单元测试结果和OpenCover的单元测试覆盖率到SonarQube服务中

    SonarQube.Scanner.MSBuild.exe begin /k:"OMDCCQuotes" /d:sonar.host.url="http://myip:9 ...

  6. Django-DRF(视图相关)

    drf除了在数据序列化部分简写代码以外,还在视图中提供了简写操作.所以在django原有的django.views.View类基础上,drf封装了多个子类出来提供给我们使用. Django REST ...

  7. 【VS开发】VSTO 学习笔记(十)Office 2010 Ribbon开发

    微软的Office系列办公套件从Office 2007开始首次引入了Ribbon导航菜单模式,其将一系列相关的功能集成在一个个Ribbon中,便于集中管理.操作.这种Ribbon是高度可定制的,用户可 ...

  8. SpringCloud学习(七)高可用的分布式配置中心(Spring Cloud Config)(Finchley版本)

    上一篇文章讲述了一个服务如何从配置中心读取文件,配置中心如何从远程git读取配置文件,当服务实例很多时,都从配置中心读取文件,这时可以考虑将配置中心做成一个微服务,将其集群化,从而达到高可用 准备工作 ...

  9. iterm 2快捷键

    快捷键 作用说明 command + f 搜索&查找,如果输入搜索内容后,按下 tab 键,就会 iTerm 自动帮选中搜索关键词,并且自动的帮我们复制到了剪贴板中.如果输入的是 shift+ ...

  10. Web安全小结之后端