Sfoglia il codice sorgente

登录及修改密码加密

daxu0403 7 anni fa
parent
commit
e0f195a541

+ 5 - 2
lib/login_page.dart

@@ -1,5 +1,7 @@
 import 'package:flutter/material.dart';
 import 'package:flutter_screenutil/flutter_screenutil.dart';
+import 'package:crypto/crypto.dart';
+import 'dart:convert';
 import 'util/session.dart';
 import 'home_page.dart';
 import 'util/api.dart';
@@ -110,12 +112,13 @@ class _LoginPageState extends State < LoginPage > {
                       setState(() {
                         loginStatus = false;
                       });
-                      login(phone,password).then((resp){
+                      String tempString = sha1.convert(utf8.encode(password)).toString();
+                      login(phone,tempString).then((resp){
                         if(isNotError(context, resp)){
                           Login loginObj = Login.fromJson(resp.data);
                           setKey('token', loginObj.data.token);
                           setKey('phone',phone);
-                          setKey('password',password);
+                          setKey('password',tempString);
                           setKey('nickName',loginObj.data.nickName);
                           setKey('printType','1');//设置打印类型
                           setKey('stationId', loginObj.data.stationIds[0].toString());//设置站点id

+ 2 - 2
lib/pages/my_page.dart

@@ -105,7 +105,7 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
           //   }
           // });
           getKey('btList').then((value) {
-            //if (value != '') {
+            if (value != '' && value!=null) {
               List tempList = [];
               for (int i = 0; i < 999; i++) {
                 if (value.indexOf('&') != -1) {
@@ -129,7 +129,7 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
                   });
                 }
               });
-            //}
+            }
           });
        }
       });

+ 7 - 3
lib/pages/my_page/revise_password_page.dart

@@ -1,5 +1,7 @@
 import 'package:flutter/material.dart';
 import 'package:flutter_screenutil/flutter_screenutil.dart';
+import 'package:crypto/crypto.dart';
+import 'dart:convert';
 import '../../util/session.dart';
 import '../../showAlert.dart';
 import '../../util/api.dart';
@@ -104,8 +106,10 @@ class _RevisePasswordPageState extends State < RevisePasswordPage > {
                       if (oldPassword == '' || newPassword == '') {
                         return;
                       }
+                      String tempString = sha1.convert(utf8.encode(oldPassword)).toString();
+                      String newTempString = sha1.convert(utf8.encode(newPassword)).toString();
                       getKey('password').then((value) {
-                        if (value != oldPassword) {
+                        if (value != tempString) {
                           showDialog < Null > (
                             context: context, //BuildContext对象
                             barrierDismissible: false,
@@ -118,9 +122,9 @@ class _RevisePasswordPageState extends State < RevisePasswordPage > {
                           setState(() {
                             loginStatus = false;
                           });
-                          updataPasswrod(oldPassword, newPassword).then((resp) {
+                          updataPasswrod(tempString, newTempString).then((resp) {
                             if (isNotError(context, resp) && this.mounted) {
-                              setKey('password', newPassword);
+                              setKey('password', newTempString);
                               showDialog < Null > (
                                 context: context, //BuildContext对象
                                 barrierDismissible: false,

+ 14 - 0
pubspec.lock

@@ -36,6 +36,13 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "1.14.11"
+  convert:
+    dependency: transitive
+    description:
+      name: convert
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "2.1.1"
   cookie_jar:
     dependency: transitive
     description:
@@ -43,6 +50,13 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "1.0.0"
+  crypto:
+    dependency: "direct main"
+    description:
+      name: crypto
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "2.0.6"
   cupertino_icons:
     dependency: "direct main"
     description:

+ 2 - 0
pubspec.yaml

@@ -33,6 +33,8 @@ dependencies:
   url_launcher: ^5.0.1
   #格式化日期包
   intl: ^0.15.8
+  #加密包
+  crypto: ^2.0.6
 
 dev_dependencies:
   flutter_test: