FrankieD FrankieD - 5 days ago 4
Python Question

Python simple login

I have assignment in my school to create function with simple login from some file (users.txt) I'm not very good at Python 3.5 so I need help.




Data in users.txt looks like this:

Name|Surname|username|password

separated by "|"




My job is to create simple login when program starts and continue to main_menu() if username and password input matches with one in users.txt file.

Thx :)

ps. I'm not supposed to use any advanced methods for login :(

Answer
def main_menu():
    print('successfull login!')

if __name__ == '__main__':
    user_name = input('Enter user name:')
    password = input('Enter password:')

    f = open('users.txt')
    file_content = f.read()
    users = file_content.split('\n')
    print(users)
    for user in users:
        user_array = user.split('|')
        current_username = user_array[2]
        current_password = user_array[3]
        if (current_username == user_name and current_password == password):
            main_menu()

Enjoy!