Skip to main content

NFC with Custom Scripts in TheFlex

Writing Login Data to Your NFC Chip in TheFlex

To store login data on an NFC chip using theFlex, proceed as follows:

  1. Navigate to Settings > Useful Tools > NFC Writer.
  2. Select text/pg from the dropdown menu.
  3. Enter your email address or username in the first input field.
  4. Enter your password in the second input field.
  5. Hold your NFC chip to the back of your device until it vibrates.
  6. Tap the blue button to write the data onto the NFC chip.

If no error message appears, you can return and open the NFC Reader. Again, select text/pg in the dropdown. Hold the chip to your device—your previously saved information should now be displayed.

Creating a Custom Script to Read the NFC Chip

To ensure that the script is executed only on the intended login page, the exact URL of the login page should be specified. Below is an example of how an automated NFC login script for Microsoft might look. After reading the NFC chip, the login process will proceed automatically:

document.addEventListener("deviceready", function() {
function showNFCData(username, password) {
alert("Username: " + username + "\nPassword: " + password);

var emailInput = document.querySelector('input[type="email"]');
var checkEmailInterval;
if (emailInput) {

var emailAddress = username.toLowerCase();

emailInput.value = emailAddress;
emailInput.blur();

checkEmailInterval = setInterval(function() {
var emailConfirmationButton = document.querySelector('button, input[type="submit"]');
if (emailConfirmationButton) {
clearInterval(checkEmailInterval);
emailConfirmationButton.click();
checkPassword(password);
}
}, 1000);
}

}
function checkPassword(userPassword) {
var checkPasswordInterval = setInterval(function() {
var passwordInput = document.querySelector('input[type="password"]');
if (passwordInput) {
var confirmationButton = document.querySelector('input[type="submit"]');
if (confirmationButton) {
passwordInput.value = userPassword;
passwordInput.blur();
clearInterval(checkPasswordInterval);
confirmationButton.click();
}
}
}, 1000);
}

function checkCheckbox() {
var checkCheckboxInterval = setInterval(function() {
var confirmationCheckbox = document.querySelector('input[type="checkbox"]');
if (confirmationCheckbox) {
clearInterval(checkCheckboxInterval);
confirmationCheckbox.checked = true;

var backButton = document.getElementById('idBtn_Back');

if (backButton) {
backButton.focus();
backButton.click();
}
}
}, 1000);
}


checkCheckbox();

nfc.addNdefListener(
function (nfcEvent) {
var message = nfcEvent.tag.ndefMessage;

var usernamePayload = message[0];
var username = nfc.bytesToString(usernamePayload.payload).toLowerCase();

var password = "";
if (message.length > 1) {
var passwordPayload = message[1];
password = nfc.bytesToString(passwordPayload.payload);
}

showNFCData(username, password);
},
function () {
console.log('Scann failed');
}

);
});

FAQ

On a regular desktop-style web page, can we extract and display only the required fields in the TheFlex Browser?

Yes, it is possible to selectively extract specific fields from a web page using custom scripts. With JavaScript, you can target elements by their ID or class, retrieve their values, and display only the relevant fields in the TheFlex Browser’s interface.

Can custom scripts work effectively on dynamic pages, such as those built with AJAX?

Yes, custom scripts can also be utilized on dynamic pages. By using approaches like Mutation Observers, event listeners, or periodic checks (e.g., setInterval), scripts can respond to dynamically loaded or updated DOM elements, ensuring your logic runs at the appropriate time.

Can features like NFC or OCR be triggered automatically when a user clicks on specific input fields or buttons, without needing to modify the original web page?

Yes, using custom scripts, you can add event listeners (e.g., for clicks on elements with specific IDs) to trigger actions such as starting an NFC scan or OCR processing. This can be accomplished without changing the source code of the original page.

What security considerations should be taken into account when storing login data on NFC chips?

NFC chips generally store data unencrypted. It is recommended to encrypt sensitive information and, where possible, only store it temporarily on the chip. Appropriate permissions and secure handling should be ensured.

Are access logs or error reports available to trace issues with NFC transactions?

Depending on the implementation, logs and error reports can be enabled for troubleshooting. This helps to track processes and identify possible sources of errors during operation.

What happens if an NFC tag is damaged or incompatible?

The script can detect errors when reading or writing and provide respective messages. It is advisable to include proper error handling and compatibility checks in the implementation.