This tool works but we want something not online. I used that tool for proof of concept so to speak.
The below code works to create a 128 barcode but it’s not submitting the credentials as in clicking enter to login. The username and password field data populates from the scan but it’s not logging in automatically.
Would someone be so kind as to help me please?
The goal is to scan the barcode and it enters the credentials, followed by auto login. no interaction but to scan the barcode.
Thank you very much in advance.
import barcode
from barcode.writer import ImageWriter
import re
def generate_barcode(data, filename):
# Generate barcode image without text below it
ean = barcode.get('code128', data, writer=ImageWriter())
ean.save(filename, options={"write_text": False})
if __name__ == "__main__":
# Replace 'YourUsername' and 'YourPassword' with your actual username and password
username = "username@email.com"
password = "helpmeplease"
# Extract the username before the "@" symbol
username_prefix = re.match(r'^([^@]+)@', username).group(1)
# Concatenate username and password with a tab delimiter
data = f"{username}\t{password}"
# Generate barcode with encoded data and save it with the username prefix as the filename
generate_barcode(data, f"{username_prefix}.png")
print("Barcode generated successfully without credentials.")
I don’t really know the expected formats, but based on reading the websites source code, you should be able to put ^013 after the password to send an “ENTER” signal. (13 being the decimal ASCII code for carriage return). The website also uses ^009 instead of \t for tab, not sure if that is a relevant difference.
import barcode
from barcode.writer import ImageWriter
import re
def generate_barcode(data, filename):
# Generate barcode image without text below it
ean = barcode.get('code128', data, writer=ImageWriter())
ean.save(filename, options={"write_text": False})
if __name__ == "__main__":
# Replace 'YourUsername' and 'YourPassword' with your actual username and password
username = "user@email.com"
password = "password"
# Extract the username before the "@" symbol
username_prefix = re.match(r'^([^@]+)@', username).group(1)
# Concatenate username and password with a tab delimiter
# Include the ASCII code for "Enter" (13) after the password to simulate the "Enter" key press
data = f"{username}\t{password}\x0D"
# Generate barcode with encoded data and save it with the username prefix as the filename
generate_barcode(data, f"{username_prefix}.png")
print("Barcode generated successfully without credentials.")
My next portion is to get this to work in sharepoint on the backend of a form.
since it appears that you are formalizing this into a serious app:
Recommendations:
Test that email is entered in correct format by operator. For example,
validate that emails are entered with acceptable characters in the username.
As it is currently written, the following emails are acceptable:
a. sam,#&@.email.com
b. eric…$!@some.com
It only checks if the @ character is present. If it is present, everything else
appears to be fair game.
You can also add a try/except pair to check that it is entered correctly
so that it doesn’t crash if an erroneous format is entered by the operator.
For example, if you enter the email without the @ by mistake, it will crash the
app. This pair catches the error and gives you the opportunity to rectify it, i.e.,
a message to the operator to re-enter the email/username correctly, for example.
Put code below the main file test condition in a loop. Otherwise, as is, it only
runs once. A potential solution is to put that code in a function on top. Then
below, enter it like:
while(True):
function_name() # Give it any name you want where code is entered