Python Forum
[Python Learning]Verifying user name / password in website with simple python code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Python Learning]Verifying user name / password in website with simple python code
#1
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
Reply
#2
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.
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Learning Python, advice on current project Yahweh132 0 1,779 Feb-23-2022, 06:07 AM
Last Post: Yahweh132
  Simple Recursive-Descent Parser - Python 3.7 WannaBePythonDev 4 3,117 Sep-13-2021, 05:29 PM
Last Post: WannaBePythonDev
  Simple password generator using a module I made myself Fr4nkl1n_1k3h 3 2,425 Aug-07-2020, 01:06 PM
Last Post: Fr4nkl1n_1k3h
  First time python user - Calculator code review Steamy 1 2,222 Jul-22-2020, 05:59 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020