Use regular storage for pass
This commit is contained in:
parent
b3907d0c6c
commit
930fc53767
3 changed files with 16 additions and 6 deletions
|
|
@ -1,13 +1,22 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:traccar_client/l10n/app_localizations.dart';
|
||||
import 'package:traccar_client/preferences.dart';
|
||||
|
||||
class PasswordService {
|
||||
static final FlutterSecureStorage _secureStorage = const FlutterSecureStorage();
|
||||
static const String _passwordKey = 'password';
|
||||
|
||||
static Future<void> migrate() async {
|
||||
final oldPassword = await _secureStorage.read(key: _passwordKey);
|
||||
if (oldPassword == null) return;
|
||||
await Preferences.instance.setString(_passwordKey, oldPassword);
|
||||
await _secureStorage.delete(key: _passwordKey);
|
||||
}
|
||||
|
||||
static Future<bool> authenticate(BuildContext context) async {
|
||||
if (!await _secureStorage.containsKey(key: _passwordKey)) return true;
|
||||
final storedPassword = Preferences.instance.getString(_passwordKey);
|
||||
if (storedPassword == null || storedPassword.isEmpty) return true;
|
||||
final controller = TextEditingController();
|
||||
bool? result;
|
||||
if (context.mounted) {
|
||||
|
|
@ -28,9 +37,8 @@ class PasswordService {
|
|||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
final password = await _secureStorage.read(key: _passwordKey);
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context, password == controller.text);
|
||||
Navigator.pop(context, storedPassword == controller.text);
|
||||
}
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.okButton),
|
||||
|
|
@ -50,9 +58,9 @@ class PasswordService {
|
|||
|
||||
static Future<void> setPassword(String password) async {
|
||||
if (password.isNotEmpty) {
|
||||
await _secureStorage.write(key: _passwordKey, value: password);
|
||||
await Preferences.instance.setString(_passwordKey, password);
|
||||
} else {
|
||||
await _secureStorage.delete(key: _passwordKey);
|
||||
await Preferences.instance.remove(_passwordKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue