Share your repls and programming experiences

← Back to all posts
Login program
TripleJ123 (7)

A little login program I created. Please suggest more ideas or faults in the comments.

DrAvery (15)

I made my own "Login/Register" Python program a while back. You can find that here:

Although the code is written for Tkinter, the same idea would apply to a console or IDE driven version of this; load a json file (create one if it doesn't exist, dumping an empty json dictionary to it so you are able to read and write json data without any errors and whatnot) so you are able to check whether a given username exists, and, if it does, that the given password for that username is the one that is stored.

Also, I used SHA3_256 to encrypt the password, making it so that the password is not stored in plain text in a text file. By encrypting the password with a function when a user first registers, you can then make a dictionary with the username as the key and the encrypted password as the value of that key. An example of such for a console or IDE driven version would be as follows:

Username: DrAvery
Password: Password

The haslibs module for Python would then take the password "Password" and encrypt it with SHA3_256, which is "e7cf3ef4f17c3999a94f2c6f612e8a888e5b1026878e4e19398b23bd38ec221a." We can then create the Python dictionary:

usernames_and_passwords = {
"DrAvery": "e7cf3ef4f17c3999a94f2c6f612e8a888e5b1026878e4e19398b23bd38ec221a"

Using this Python dictionary, we can then use a json.dump() and dump the json output to a file.

When you want to check if a given username and the associated password exist, you would write something simmilar to the following:

for i in usernames_and_passwords:
... code stuff here ...

I hope this helped,
Dr. Avery

HappyFakeboulde (237)

and have some system of saving logins in an external file

HappyFakeboulde (237)

You should encrypt the passwords

WonderNote18 (6)

You should add try/except checks so that if someone entered blank input (just spamming enter) it would go through the checks in the loops instead of bypassing your loop's arguments. Through this error, I was able to login with a blank username/password.

inputusername = input("What is the username?")
except SyntaxError:
inputusername = None

If the input above returns a SyntaxError, it'll return the variable with a value of None instead of no value at all. Otherwise, it will return the variable with whatever value was inputted.