Browse Source

[完善]存储本地密码加密

dev
邵佳豪 3 years ago
parent
commit
37dc7baca6
  1. 5
      package-lock.json
  2. 1
      package.json
  3. 14
      src/app/pages/login/login.component.ts

5
package-lock.json generated

@ -9843,6 +9843,11 @@
}
}
},
"js-base64": {
"version": "3.7.2",
"resolved": "https://registry.npmmirror.com/js-base64/download/js-base64-3.7.2.tgz",
"integrity": "sha1-gW0R2BqK/yQWA9Gc5XYeE+Qdd0U="
},
"js-levenshtein": {
"version": "1.1.6",
"resolved": "https://registry.npm.taobao.org/js-levenshtein/download/js-levenshtein-1.1.6.tgz",

1
package.json

@ -40,6 +40,7 @@
"echarts": "^4.9.0",
"firebase": "^7.6.2",
"install": "^0.13.0",
"js-base64": "^3.7.2",
"linqjs": "^1.0.2",
"moment": "^2.29.1",
"ng-zorro-antd": "^9.3.0",

14
src/app/pages/login/login.component.ts

@ -5,7 +5,7 @@ import { CacheTokenService } from '../../service/cache-token.service'//引入服
import { CookieService } from 'ngx-cookie-service';//cookie插件
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { NzMessageService } from 'ng-zorro-antd/message';
import { Base64 } from 'js-base64';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
@ -30,8 +30,8 @@ export class LoginComponent implements OnInit {
let password = localStorage.getItem('password')
if (account && password) {
this.validateForm.patchValue({
userName: localStorage.getItem('account'),
password: localStorage.getItem('password')
userName: Base64.decode(localStorage.getItem('account')),
password: Base64.decode(localStorage.getItem('password'))
});
this.remember = true //这一步是回显后让勾选框为选中状态
}
@ -40,7 +40,7 @@ export class LoginComponent implements OnInit {
this.submitForm()
this.autologin = true //这一步是回显后让勾选框为选中状态
}
}
errmsg: string = ''; //错误信息
@ -57,8 +57,8 @@ export class LoginComponent implements OnInit {
rememberInfo() {
// 判断用户是否勾选记住密码,如果勾选,在本地储存中储存登录信息
if (this.remember) {
localStorage.setItem("account", this.validateForm.value.userName)
localStorage.setItem("password", this.validateForm.value.password)
localStorage.setItem("account", Base64.encode(this.validateForm.value.userName))
localStorage.setItem("password", Base64.encode(this.validateForm.value.password))
}
}
//自动登陆
@ -80,7 +80,7 @@ export class LoginComponent implements OnInit {
localStorage.removeItem("account")
localStorage.removeItem("password")
}
if(!this.autologin){
if (!this.autologin) {
localStorage.removeItem("isautologin")
}

Loading…
Cancel
Save