**For my cybersecurity lab, I have to write a python program to iterate through a .txt file of passwords and a .txt file of usernames and check them against a Login.pyc file (that takes as its arguments), returning "Login successful.' if the matchup is correct. **
I'm trying to use the subprocess module to run python3 Login.pyc <user> <password>
on the command line for each iteration. The passwords file has 100,000 passwords on it, so it is obviously taking extremely long.
import subprocess
if __name__ == "__main__":
gang = open("gang") #usernames .txt file (20 lines)
pws = open("PwnedPWs100k") #passwords .txt file (100,000 lines)
for name in gang:
print("USER = ", name)
for item in pws:
output = subprocess.run(["python3", "Login.pyc", "{}".format(name.rstrip()), "{}".format(item.rstrip())], capture_output=True, text=True).stdout.strip("\n")
if output == 'Login successful.':
print("USER:" + name + "PASSWORD:" +item)
break
pws.close()
gang.close()
UPDATE: I'm now importing the Login() function from Login.pyc, and since it uses command line arguments, I'm updating the sys.argv variables in nested loops and passing them against the Login() function. It is taking a similarly long time as my previous approach, however.
if __name__ == "__main__":
with open("gang") as gang:
with open("PwnedPWs100k") as pws:
sys.argv = [sys.argv[0], 1, 2]
for name in gang:
sys.argv[1] = name.rstrip()
for item in pws:
sys.argv[2] = item.rstrip()
while not Login.Login():
continue
else:
print("USER:" + name + "PASSWORD:" +item)
break
'''
Any ideas on optimizing the runtime?