storePinSecurely method
Store PIN with biometric protection
Implementation
Future<void> storePinSecurely(String pin, {String? username}) async {
try {
OnairosDebugHelper.log('🔐 Storing PIN with biometric protection');
// Always require biometrics for PIN storage
if (await _isBiometricsAvailable()) {
final authenticated = await _authenticateWithBiometrics('Secure your PIN with biometric authentication');
if (!authenticated) {
throw Exception('Biometric authentication required to store PIN');
}
}
// Store PIN with metadata
final pinData = {
'pin': pin,
'username': username,
'timestamp': DateTime.now().toIso8601String(),
'version': '1.0',
};
await _secureStorage.write(key: 'onairos_pin_secure', value: jsonEncode(pinData));
await _secureStorage.write(key: 'pin_storage_timestamp', value: DateTime.now().millisecondsSinceEpoch.toString());
OnairosDebugHelper.log('✅ PIN stored securely');
} catch (e) {
OnairosDebugHelper.log('❌ Error storing PIN: $e');
rethrow;
}
}