Username and Password
chiliconco (34)

I am new to python and i programmed this. It took me quite a while. It may not be much but I am proud of it! Do you have any ideas on what I could implement this into in the future?

Thanks for taking the time to check this out :)


P.S If there are any errors PLEASE let me know!!


1.1 - Fixed capital letter error upon signing up/logging in.
1.2 - Fixed whitespace error upon signing up.
1.3 - If login/sign up is mistyped, the script now re-asks the question.
1.4 - Improved naviagtion
1.5 - PASSWORDS NOW HASHED! All credit goes to @Coder100 for helping me out
immensely with this! :)

You are viewing a single comment. View All
ballpointcarrot (1)

This looks like a great start, and it looks like you had fun putting it together, which is the most important thing!

I'll try to start with quick and easy suggestions, and then work up to some more challenging ideas.

First, let's take a look at this section (Lines 12-13):

x = 0
while (x == 0):

Since x == 0 evaluates to True (you can check this in the Python prompt), you can replace this check with the following:

while True:

That way, you don't need to create an extra variable to store this value to check it!

Second, let's look at your email checker. There's some values that can pass your checking, but may not be valid email addresses:

You can make your email checker look at more details, but email checking is hard. For example, here is a talk on Youtube showing how hard it is to tell what is and isn't a valid email address (some of them are surprising!).

What I would do here to start, is take your email checker code (lines 15-17) and move it into its own function:

def is_email(email):
    return ((email.find("@") > -1) and
                (email.find('.") > -1) and
                # more checks that you need

# later on:
if is_email(email):
    print("Invalid Email."))

This will let you expand on the way you handle the email checker, while making the check itself easy to read. Making sure your code is easy is important! It makes it so others looking at it understand what your code is trying to do.

Eventually, your email checker function will become really hard to manage by having a lot of checks in it. A more advanced way of checking an email is to use a Regular Expression, or RegEx. This is a type of language used to define different types of characters, and look at how they match text provided against it.

A common regex used for email (which isn't 100% correct itself!) looks like this:

r"(^[a-zA-Z0-9_.+-][email protected][a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"

Finally, it's unsafe to store passwords in a file directly. Think about what could happen if someone were to get a copy of that file - they would have everyone's emails and passwords for this system. The best way to avoid this and keep your system secure is to not store the password at all.

But how do you make sure the password is correct if you're not storing the password?

Instead of storing the password, we can store a mathematical value that represents the password. If we take the password in, run the math against it, and make the same value as the stored value, we can say that the two passwords are the same. This is called cryptographic hashing.

Python provides a library called hashlib that can provide some of these hashing functions. This is another hard problem that could be fun to work on.

Let me know if you have any questions, and I'll try to help where I can. :D

chiliconco (34)

@ballpointcarrot Wow! Thank you for this contribution, I will get to work on the email def as soon as I have a chance (I am fixing other problems people have brought up at the moment), @Coder100 has helped me out ALOT with the hashing and I will be trying to implement that later. Thank you so much! :)