updatePin method

Future<Map<String, dynamic>> updatePin(
  1. String username,
  2. String oldPin,
  3. String newPin, {
  4. bool testMode = false,
})

Update PIN (requires old PIN verification)

Implementation

Future<Map<String, dynamic>> updatePin(String username, String oldPin, String newPin, {bool testMode = false}) async {
  try {
    OnairosDebugHelper.log('🔄 Updating PIN');

    // Verify old PIN first
    final currentPin = await retrievePinSecurely(username, testMode: testMode);
    if (currentPin == null || currentPin != oldPin) {
      return {
        'success': false,
        'message': 'Current PIN is incorrect',
        'error': 'INVALID_CURRENT_PIN',
      };
    }

    // Store new PIN
    return await storePinAfterBiometric(username, newPin, testMode: testMode);

  } catch (e) {
    OnairosDebugHelper.log('❌ Error updating PIN: $e');
    return {
      'success': false,
      'message': 'Failed to update PIN. Please try again.',
      'error': e.toString(),
    };
  }
}