若依登录需要注意的事(保存密码和加密)

本地缓存账号密码和记住密码

    getCookie() {
      const username = Cookies.get("username");
      const password = Cookies.get("password");
      const rememberMe = Cookies.get('rememberMe')
      this.loginForm = {
        username: username === undefined ? this.loginForm.username : username,
        password: password === undefined ? this.loginForm.password : decrypt(password),//解密
        rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
      };
    },

登录操作

   
    handleLogin() {   
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true;
          if (this.loginForm.rememberMe) {//存数据
            Cookies.set("username", this.loginForm.username, { expires: 30 });
            Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });//加密
            Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
          } else {//移除数据
            Cookies.remove("username");
            Cookies.remove("password");
            Cookies.remove('rememberMe');
          }
          this.$store.dispatch("Login", this.loginForm).then(() => {
            this.getLoginUserInfo()//获取当前登陆用户单位
          }).catch(() => {
            this.loading = false;
            this.loginForm.code = ""
            this.getCode();
          });
        }
      });
    },

你可能感兴趣的:(前端,安全,vue.js)