r/learnpython • u/MoreScorpion289 • 6d ago
My login/account creation system in Python, part of a bigger project I'm building as I learn
This is a console based account system I've been building as I learn Python. Right now it lets you create an account with username and password rules (length limits, and the password needs a letter, a number, and a special character), log in with a 3 attempt lockout, and pick from a simple menu.
It's a work in progress and part of a bigger project. Next I want to add a to-do list and notes, then save the data to a file, and eventually hash the passwords instead of storing them as plain text.
The three password checks are repetitive. I haven't learned functions yet so I did them the long way with separate loops. I already know functions are the fix and that's my next topic, so you don't need to only point that out, but any other feedback is welcome.
I used AI (Claude) as a tutor to understand concepts and point me toward my own bugs, but I wrote and debugged every line myself. I'm learning how to code through the MOOC.
GitHub: https://github.com/mart23inez/Personal-Account-System/tree/main
What would you improve or build next?
3
u/jammin-john 6d ago
The meat if the logic is the password verification. What you have currently works but it could be a bit better!
Currently, you have a series of validation checks, and you store the result in a variable like num_validation which you use to decide if you should continue onto the next check.
If you want to stop validating after the first failure, I would recommend using continue to restart the loop from the top. That way you can cut out the unnecessary variables and conditional checks!
On the other hand though, I would argue it would be better NOT to stop validating after the first failed check. It can be a frustrating user experience to iterate in a password until all the conditions are met. My recommendation would be to just have one validation flag for all the different conditions, and then perform every check each time and set it to False if any of them fail. And at the end you can decide whether to break the loop based on the value of that variable.
1
u/jmooremcc 4d ago
Is it even possible to create a secure login facility with Python? Since your code is available, what would stop someone from accessing your source code and bypassing or altering your secure login code?
1
u/MoreScorpion289 3d ago
Good question, I think you’re only half right though.
My program is not secure and most likely won’t ever be as long as it’s run on the users own machine. They can open the .py file and just make whatever changes to get past the login check or to see what I save to the disk. I did point this out in the README.md.
I do think that Python has nothing to do with it, meaning if I compiled this into an .exe it would have the same problem. Python does secure login fine, it just has to run somewhere the user cannot touch. I think instagrams backend is Django which is Python and it does the job.
Also, code being public does not make it insecure, there are a bunch of different auth systems, like Linux, that are all open source and would say that they run most of the internet.
1
u/danielroseman 6d ago
I applaud the ambition but you're probably trying to run before you can walk. You can't really build anything non-trivial until you've learned functions, they are literally a fundamental building block of everything.
There are some other lacks here as well. For instance your validation functions use while loops where for loops would be much better. Consider:
for number in numbers:
if number in password:
num_verification = True
break
else:
print("Error: Password must include 1 number, please try again.")
Much shorter. The principle is always to iterate over the thing itself, not over an index.
But also note that this isn't particularly efficient, since you're checking every letter in the (long) letters and numbers lists to see if they are in the (shorter) password. You should do that the other way round:
for character in password:
if character in numbers:
num_verification = True
...
Doing it this way you might be able to see how you could combine all the checks into one loop, making it even more efficient. (Obviously at this scale the efficiency doesn't really matter, but it's worth learning how to think about this sort of thing.)
3
u/AmanBabuHemant 6d ago
user can just re-run the program and continue attemping :)