import os.path
def start():
if os.path.exists("new.txt") == False:
Account = input('Username: ')
Password_for_account = input('Password: ')
all_the_content = []
all_the_content.append(Account)
all_the_content.append(Password_for_account)
else:
with open("new.txt") as file:
content = file.read()
all_the_content = content.strip('][').split(', ')
while True:
User = input('Username: ')
Password = input('Password: ')
if (User, Password) == all_the_content[0,1] :
print('Done')
break
else:
print('Invalid Password')
continue
return 'You have been succesfully logged in!'
print(start())
with open("new.txt") as file:
content = file.read()
all_the_content = content.strip('][').split(', ')
def add_new_pass():
new_username = input('Enter the new username: ')
new_password = input('Enter the new password: ')
all_the_content.append(new_username)
all_the_content.append(new_password)
return 'Your password has been added'
def check_pass(username):
position = all_the_content.index(username)
if username in all_the_content and position%2 == 0:
return 'The password for '+ username, 'is '+ all_the_content[position + 1]
else:
return 'Invalid username'
print(add_new_pass())
a = input()
print(check_pass(a))
with open ('new.txt', 'w') as file:
file.write(str(all_the_content))
I am a beginner. This code does everything as expected except one thing, every time I make thefile as "new.txt". Any help is appreciated! it stores it as "new2.txt". I am using Jupyter notebook.