Python Forum
Beginner python password program - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Beginner python password program (/thread-15579.html)



Beginner python password program - jakobscheffler - Jan-23-2019

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.


RE: Beginner python password program - ichabod801 - Jan-23-2019

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.


RE: Beginner python password program - Naito - Jan-23-2019

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':



RE: Beginner python password program - ichabod801 - Jan-23-2019

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'.


RE: Beginner python password program - Alfalfa - Jan-23-2019

You might want to use the cryptography module instead of storing plain text passwords

https://gitlab.com/william.belanger/gmail-monitor/blob/master/gmail-monitor.py