pythonreplit

How to convert a txt file into a dictionary and manage user logins in Python?


I am working on a beginner project where I need to build a login system for one admin and multiple employees. The functionalities include:

Employees can view their salary. The admin can change employee salaries. The data for employees is stored in a txt file with fields such as username and salary. I am trying to achieve the following:

Convert the txt file into a dictionary for easy manipulation by the admin. Transition from the login screen to the appropriate menu (admin or employee) based on the credentials entered. Here's the basic structure of my code:

import data
username = input("Enter a username: ")
password = input("Enter a password: ")

def log_in(username, password):
    # login logic here...

 Rest of the code...

I am struggling with the following:

How do I effectively convert the txt file into a dictionary in the main function? Once a user is authenticated, how can I transition to the appropriate menu based on their role? Any assistance or hints would be much appreciated.


Solution

  • Read the text file in, convert into CSV. See here Python csv