Python Forum
Username and password
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Username and password
#11
Hi,

Still the same problem with the else :(

def user_name():
   with open("password.txt","r") as access:
       for line in access:
          words = line.splite()
       s = input("Enter a username: ")
       user_index = None
       for index, user in enumerate(text):
           if s in user:
               user_index = index
               if user_index is None:
                   print("User not found")

                   else: #invalid  syntax
                       s = input("Enter a password: ")
                       if s in text[user_index]:
                           #user_name()
Reply
#12
In line 4, you misspelled word. Line 13's indentation is incorrect, it should line up with it's respective "if"
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#13
I have adjusted the else, it now keeps highlighting the last if and stating it is an unexpected eof error. Not sure why.


def user_name():
   with open("password.txt","r") as access:
       for line in access:
          word = line.splite()
       s = input("Enter a username: ")
       user_index = None
       for index, user in enumerate(text):
           if s in user:
               user_index = index
               if user_index is None:
                   print("User not found")

               else:
                  s = input("Enter a password: ")
                  if s in text[user_index]:
Reply
#14
Got it working however its not doing what I require at this stage. for instance in my textfile
I have
John go
Adam no

It doesnt accept Adam a username or the password


def user_name():
    # open the file and read data
    text = []
    with open("password.txt","r") as access:
        for line in access:

            text.append(line.split())  # store data in a list
 
    # continue with rest of the code
    name = input("Enter a username: ")
    for index, user in enumerate(text):
        user_index = None  # moved to inside the loop
        if name in user:
            user_index = index
        if user_index is None:
            print("User not found")
  
        else:
            password = input("Enter a password: ")
            if password in text[user_index]:
                print("password correct")
user_name()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  function-decorator , which is checking an access according to USERNAME Liki 6 430 Feb-17-2024, 03:36 AM
Last Post: deanhystad
  python code tp determin a userName and print message jackAmin 4 1,752 Nov-20-2022, 12:03 AM
Last Post: rob101
  Help! Chatting App - Changing the "IP & Port" into Username Rowan99 0 1,372 Dec-20-2021, 07:02 AM
Last Post: Rowan99
  Password and Username Verification AlwaysNew 4 17,062 Nov-12-2017, 11:51 AM
Last Post: wavic

Forum Jump:

User Panel Messages

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