1

I'm working on a simple "sign in " "sign up" program, and the idea is that the user inputs a username and a password and they get saved in a python file named Database. And the sign in process works the same, but I'm stuck in the step where the program should import a class named after the username that has the password in it, and to import this class the user should input its name (username) so at first it will be just a variable and later it will be defined. I'm still a beginner in python and this is my idea as a code:

#This is the file named Database class Username: password = ["Mypassword"] 
#This is the sign in program user = input("enter your username:\n") with open('Database.py') as file: content = file.read() if user in content: from Database import user else: print("this username is not in the database") 

in the console it shows that "user" is not defined because it's a variable, so is there any other way to achieve the same goal with another function or something. This is the best I can think of as a beginner perhaps if someone has a better idea let me know please.

1
  • The way you use the word import makes it sound like it means something different to you than it does to python. Please update your knowledge by referring to the documentation or some tutorials. Commented Aug 23, 2022 at 11:36

2 Answers 2

3

I suggest having class User, which saves name and password in a txt file once the object has been created. It opens .txt file, adds a line, and closes it. After that in the main function you can open the txt file and iterate through as many times as you want and check if it contains a certain user. Hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

1

So if i understand correctly there is no user in the Database file. There are one way of solving the problem that i can think of learn some pandas(its module) and create a table with unsernames and passwords(its gona be 10 times easier than what you trying to do)

AND

As @jokkk2312 dont read a python file you can create a text file that will save the username and password as one(e.x username:panos password:123 in the file save it as one string: panos123 and put \n so it changes row every time.) After that make a program that ask you for your user name and password and combines them to a single string. You take than string and search the hole file for the same string....

If you want me to create a code example add a comment to this post and i will make one...

1 Comment

Sure I'll try what you said and I think it'll work

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.