Python Forum

Full Version: Beginner python password program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
print('\n')

print('uPass 1.0')




menu = input('Create - Y, Enter N: ')

if menu == 'Y' or menu == 'y':

    new_pass = input('Enter new password: ')
    file = open('uPass_pass.txt', 'w')
    file.write(new_pass)
    file.close()

    print_password = open('uPass_pass.txt', 'r')
    print(print_password.read())
    file.close()

elif menu == 'N' or menu == 'n':

    pass_input = input('Enter password: ')
    file = open('uPass_pass.txt', 'r')
    if pass_input == file:
        print('working')
    else:
        print('error')
This is my attempt at creating a program that lets the user create a password that is stored and can be called upon when the user enters the password and the program should determine if it is the correct or incorrect password. This program is very unfinished and in trial stages but I cannot figure out how to store the password in the text file that I have created. I am using PyCharm and have created the python file and text file names uPass_pass.txt. Any help is appreciated and I have tried to write this without help of other modules to challenge myself.
Line 25. file is the file object, not the contents of the file. You need to read file contents like you do on line 18.
Hello, line 25 is missing .read()
if pass_input == file.read():
also user .lower() to convert automatically user input from uppercase to lowercase:
if menu.lower() == 'Y':
elif menu.lower() == 'N':
You need the lower method on the input, not the target:

if menu.lower() == 'y':
    ...
elif menu.lower() == 'n':
    ...
menu == 'N'.lower() is the same as menu == 'n'.
You might want to use the cryptography module instead of storing plain text passwords

https://gitlab.com/william.belanger/gmai...monitor.py