Skip to content

Commit

Permalink
Remove password encryption (#1259)
Browse files Browse the repository at this point in the history
  • Loading branch information
limwa authored Jul 2, 2024
2 parents ad5568e + 289cd19 commit 5176491
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 44 deletions.
30 changes: 3 additions & 27 deletions uni/lib/controller/local_storage/preferences_controller.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:io';

import 'package:encrypt/encrypt.dart' as encrypt;
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:shared_preferences/shared_preferences.dart';
Expand All @@ -17,10 +16,6 @@ import 'package:uni/utils/favorite_widget_type.dart';
class PreferencesController {
static late SharedPreferences prefs;

static final iv = encrypt.IV.fromBase64('jF9jjdSEPgsKnf0jCl1GAQ==');
static final key =
encrypt.Key.fromBase64('DT3/GTNYldhwOD3ZbpVLoAwA/mncsN7U7sJxfFn3y0A=');

static const _lastUpdateTimeKeySuffix = '_last_update_time';
static const String _userNumber = 'user_number';
static const String _userPw = 'user_password';
Expand Down Expand Up @@ -79,7 +74,7 @@ class PreferencesController {
List<String> faculties,
) async {
await _secureStorage.write(key: _userNumber, value: user);
await _secureStorage.write(key: _userPw, value: encode(pass));
await _secureStorage.write(key: _userPw, value: pass);
await prefs.setStringList(
_userFaculties,
faculties,
Expand Down Expand Up @@ -195,9 +190,8 @@ class PreferencesController {
}

/// Returns the user's password, in plain text format.
static Future<String?> getUserPassword() async {
final password = await _secureStorage.read(key: _userPw);
return password != null ? decode(password) : null;
static Future<String?> getUserPassword() {
return _secureStorage.read(key: _userPw);
}

/// Replaces the user's favorite widgets with [newFavorites].
Expand Down Expand Up @@ -273,24 +267,6 @@ class PreferencesController {
);
}

/// Encrypts [plainText] and returns its base64 representation.
static String encode(String plainText) {
final encrypter = _createEncrypter();
return encrypter.encrypt(plainText, iv: iv).base64;
}

/// Decrypts [base64Text].
static String? decode(String base64Text) {
final encrypter = _createEncrypter();
return encrypter.decrypt64(base64Text, iv: iv);
}

/// Creates an [encrypt.Encrypter] for encrypting and decrypting the user's
/// password.
static encrypt.Encrypter _createEncrypter() {
return encrypt.Encrypter(encrypt.AES(key));
}

static bool getTuitionNotificationToggle() {
return prefs.getBool(_tuitionNotificationsToggleKey) ?? true;
}
Expand Down
16 changes: 0 additions & 16 deletions uni/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.4.2"
asn1lib:
dependency: transitive
description:
name: asn1lib
sha256: c9c85fedbe2188b95133cbe960e16f5f448860f7133330e272edbbca5893ddc6
url: "https://pub.dev"
source: hosted
version: "1.5.2"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -361,14 +353,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.17"
encrypt:
dependency: "direct main"
description:
name: encrypt
sha256: "62d9aa4670cc2a8798bab89b39fc71b6dfbacf615de6cf5001fb39f7e4a996a2"
url: "https://pub.dev"
source: hosted
version: "5.0.3"
expansion_tile_card:
dependency: "direct main"
description:
Expand Down
1 change: 0 additions & 1 deletion uni/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ dependencies:
currency_text_input_formatter: ^2.1.5
diacritic: ^0.1.5
email_validator: ^2.0.1
encrypt: ^5.0.3
expansion_tile_card: ^3.0.0
flutter:
sdk: flutter
Expand Down

0 comments on commit 5176491

Please sign in to comment.