Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing password encoding in local storage #1245

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions uni/lib/controller/local_storage/preferences_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class PreferencesController {
List<String> faculties,
) async {
await _secureStorage.write(key: _userNumber, value: user);
await _secureStorage.write(key: _userPw, value: pass);
await _secureStorage.write(key: _userPw, value: encode(pass));
await prefs.setStringList(
_userFaculties,
faculties,
Expand Down Expand Up @@ -175,6 +175,7 @@ class PreferencesController {
static Future<Tuple2<String, String>?> getPersistentUserInfo() async {
final userNum = await getUserNumber();
final userPass = await getUserPassword();

if (userNum == null || userPass == null) {
return null;
}
Expand Down Expand Up @@ -281,11 +282,7 @@ class PreferencesController {
/// Decrypts [base64Text].
static String? decode(String base64Text) {
final encrypter = _createEncrypter();
try {
return encrypter.decrypt64(base64Text, iv: iv);
} catch (_) {
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is to sentry catch the error

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a relevant error for sentry to catch? This happens if the password was encrypted with a different key/IV - we changed it ourselves - or if the store gets miraculously corrupted - unlikely. But in either case, we just want the user to perform login again, no?
Either way, if we wanted the exception to go to sentry, wouldn't it be better to add the code in the catch block to report the exception and return null either way?

}
return encrypter.decrypt64(base64Text, iv: iv);
}

/// Creates an [encrypt.Encrypter] for encrypting and decrypting the user's
Expand Down
4 changes: 2 additions & 2 deletions uni/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1343,10 +1343,10 @@ packages:
dependency: "direct main"
description:
name: ua_client_hints
sha256: "8401d7bec261f61b3d3b61cd877653ddf840de2d9e07bd164f34588572aa0c8b"
sha256: ee3da4e4b6ed211fe54deaa19832dd25613f11fc2951912d4e62a093da03fbbb
url: "https://pub.dev"
source: hosted
version: "1.2.2"
version: "1.3.1"
unicode:
dependency: transitive
description:
Expand Down
Loading