Programme that checks if password is in file. File is from a different programme that generates a password. The problem is that I want to check if the exact password is in the file not parts of the password. Passwords are each on newlines.
For example, when password = 'CrGQlkGiYJ95' : If user enters 'CrGQ' or 'J95' or 'k' : the output is true. I want it to output True for only the exact password.
I tried '==' instead of 'in' but it outputs False even if password is in file. I also tried .readline() and .readlines() instead of .read(). But both output false for any input.
FILENAME = 'passwords.txt'
password = input('Enter your own password: ').replace(' ', '')
def check():
with open(FILENAME, 'r') as myfile:
content = myfile.read()
return password in content
ans = check()
if ans:
print(f'Password is recorded - {ans}')
else:
print(f'Password is not recorded - {ans}')
in