post_enrollment_app/lib/pages/session/authenticationService.dart
2025-05-02 14:12:59 +05:30

50 lines
1.5 KiB
Dart
Executable File

import 'package:local_auth/local_auth.dart';
import 'package:shared_preferences/shared_preferences.dart';
class AuthService {
final LocalAuthentication _localAuth = LocalAuthentication();
Future<bool> authenticateWithBiometrics() async {
try {
bool canCheckBiometrics = await _localAuth.canCheckBiometrics;
bool isDeviceSupported = await _localAuth.isDeviceSupported();
if (canCheckBiometrics && isDeviceSupported) {
bool authenticated = await _localAuth.authenticate(
localizedReason: 'Scan your fingerprint to authenticate',
);
return authenticated;
} else {
return false;
}
} catch (e) {
return false;
}
}
Future<void> saveBiometricEnableKey(status) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setBool('biometricStatus', status);
}
Future<void> saveSkipStatus(status) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setInt('skipStatus', status);
}
Future<void> savePin(String pin) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('user_pin', pin);
}
Future<String?> getPin() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString('user_pin');
}
Future<void> clearPin() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.remove('user_pin');
}
}