<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. LC 638. Shopping Offers

    In LeetCode Store, there are some kinds of items to sell. Each item has a price. However, there are ...

  2. Tween(补间)动画

    视图动画,也叫Tween(补间)动画可以在一个视图容器内执行一系列简单变换(位置.大小.旋转.透明度).譬如,如果你有一个TextView对象,您可以移动.旋转.缩放.透明度设置其文本,当然,如果它有 ...

  3. PCL点云库(Point Cloud Library)简介

    博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=29 什么是PCL PCL(Point Cloud Library)是在吸收了 ...

  4. 小D课堂 - 新版本微服务springcloud+Docker教程_4-06 Feign核心源码解读和服务调用方式ribbon和Feign选择

    笔记 6.Feign核心源码解读和服务调用方式ribbon和Feign选择         简介: 讲解Feign核心源码解读和 服务间的调用方式ribbon.feign选择             ...

  5. ES 可视化工具

    1.ElasticSearch Head 用途:展示ES(集群)数据信息 视图:https://mobz.github.io/elasticsearch-head/ 下载:https://github ...

  6. WMPageController设置menuView的左右视图

    效果图如下: 绿色的是自定义的emenuView的rightView哟!!! 代码实现如下: // // CategoryVC.m // JSHui // // Created by Apple on ...

  7. Laravel的Nginx重写规则--让路由支持末尾加斜线

    默认laravel路由末尾不能加/,如果加了斜线会报404 要想支持url末尾的斜线需要在public/index.php加入如下代码: $_SERVER['REQUEST_URI'] = trim( ...

  8. 增强for循环的简单总结

    整体来说:增强型for循环使用起来比较方便,代码也比较简单,如果只是操作集合中元素的而不使用索引的话,建议用此方法.对于普通for循环,如果需要使用索引进行其它操作的话,建议用这个. 详细来说:1,区 ...

  9. k8s 管理机密信息

    一.启动应用安全信息的保护: Secret介绍: 应用启动过程中可能需要一些敏感信息,比如访问数据库的用户名密码或者秘钥.将这些信息直接保存在容器镜像中显然不妥,Kubernetes 提供的解决方案是 ...

  10. 软件测试第2周个人作业:WordCount编码测试

    一.Github地址 https://github.com/zhouyubei/WordCount 二.PSP表格 PSP2.1 PSP阶段 预估耗时 (分钟) 实际耗时 (分钟) Planning ...