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

Unable to Set or Remove Password #189

Open
krishna2730 opened this issue May 17, 2024 · 0 comments
Open

Unable to Set or Remove Password #189

krishna2730 opened this issue May 17, 2024 · 0 comments

Comments

@krishna2730
Copy link

I encountered an issue while attempting to set or remove a password using the flutter-nfc-manager library. Despite following the documented instructions, the password setting/removing functionality does not seem to work as expected.Steps to Reproduce:Initialize the NFC manager in the Flutter app.Attempt to set a password using the provided method.Verify if the password was successfully set.Try to remove the password using the appropriate function.Confirm whether the password removal was successful.Expected Behavior:
The library should allow users to both set and remove passwords as documented without any errors or unexpected behavior.Actual Behavior:
The password setting/removing functions either do not execute as expected or produce errors, rendering the feature non-functional.

this is my code:
void _setPassword(String password) {
NfcManager.instance.startSession(
onDiscovered: (NfcTag tag) async {
try {
var mifareUltralight = MifareUltralight.from(tag);
if (mifareUltralight == null) {
throw Exception('Tag is not compatible with Mifare Ultralight.');
}

    int pageOffset = 0xE5;
    Uint8List passwordBytes = Uint8List.fromList(password.codeUnits);
    await mifareUltralight.writePage(pageOffset: pageOffset, data: passwordBytes);

    pageOffset = 0xE6;
    Uint8List pack = Uint8List.fromList([0x00, 0x00]);
    await mifareUltralight.writePage(pageOffset: pageOffset, data: pack);

    pageOffset = 0xE3; 
    Uint8List auth0Byte = Uint8List.fromList([0x04]);
    await mifareUltralight.writePage(pageOffset: pageOffset, data: auth0Byte);

    print('Password set successfully');
    result.value = 'Password set successfully';
  } catch (e) {
    if (e is PlatformException && e.code == 'io_exception' && e.message == 'Tag was lost.') {
      print('Error setting password: Tag was lost during write operation.');
      result.value = 'Error setting password: Tag was lost during write operation.';
    } else {
      print('Error setting password: $e');
      result.value = 'Error setting password: $e';
    }
  } finally {
    NfcManager.instance.stopSession();
  }
},

);
}

I followed steps mentioned here: https://forum.dangerousthings.com/t/inquiry-regarding-nfc-tag-password-protection-for-nxp-ntag216/21878/7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant