Python Forum
[Python Learning]Verifying user name / password in website with simple python code - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Code Review (https://python-forum.io/forum-46.html)
+--- Thread: [Python Learning]Verifying user name / password in website with simple python code (/thread-26164.html)



[Python Learning]Verifying user name / password in website with simple python code - DDE_Server - Apr-22-2020

hi Everybody Blush Blush ,
i am beginner in programming but while learning statement/loops/lists in python i coded simple code to check user name/password against stored one as you could see below:
although it still very very simple but i am feeling happy to accomplish something while i am learning:
User_names_database = ['user_name']
password_database = ['0123456']
"""prompt user to enter his/her username"""
entered_user_name = input("Please enter the user name:")
entered_user_name.title()
entered_password = input("please enter your password:")

"""Check if the entered user name/password existing in the user data base of the website"""
if entered_user_name == 'user_name' and entered_password == '0123456':
    print('login Successful,you will be shortly redirected to your account page')
else:
    print('login fail,please try again\nif you cannot remember you should choose forget password below')
    while True:
        entered_user_name = input("Please enter the user name:")
        entered_user_name.title()
        entered_password = input("please enter your password:")
        if entered_user_name == ' user_name' and entered_password == '0123456':
            print('login Successful,you will be shortly redirected to your account page')
really i know i this is very basic but i am feeling happy
i think this may be linking with back end database of course with some code scalability to be more dynamic
so Guys what is your opinion ?? i am happy to know your feedback
Note:this code is written in python language


RE: [Python Learning]Verifying user name / password in website with simple python code - micseydel - Apr-23-2020

I definitely have feedback, but I'm not sure the right way to go about it... at this point, here's what I recommend:
  • Write tests. Try to break your code. I can see at least one bug.
  • Add comments to your code explaining what you think it's doing (e.g. the .title() calls).
  • If you can cleanup the duplicated lines, that would be ideal as well.

Hint: At least four lines can be removed without changing the behavior of your code.


RE: [Python Learning]Verifying user name / password in website with simple python code - MohammedSohail - May-07-2020

It works perfectly fine but,it would be better if you haven't defined the password yet and let the user create one first and then check if the login == registration.