Python Forum
lowercasing to strings before comparison
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
lowercasing to strings before comparison
#1
I have some code for logging in. Like most logins, I don't care about uppercase and lowercase for the username. Is there a way I can lowercase all the letters inside both usernames before comparison

Sorry I should have just looked this up before posting

Actually I have a new problem. I have this function for signing in. I can lowercase what the player types in for the username and I have a list of all the username lowercased. How do i identify the original username from the dictionary of Sign ins. Here's the code -
def SignIn():
    global username
    signInListlower = []
    for i in signInList:
        signInListlower.append(string.lower(i))
    username = input('(Type "new" for new account) Type in username: ')

    if username == 'new':
        newUsername = input('Type your Username: ')
        if string.lower(newUsername) in signInListlower:
            print('The username %s is already taken' %newUsername)
            SignIn()
        else:
            newPassword = input('Type your Password: ')
            username = newUsername
            print('Now return to Destination and confirm')
            signInList.update({newUsername : newPassword})
            UserDefense.update({newUsername : 1})
            UserLvl.update({newUsername : 1})
            UserExp.update({newUsername : 0})
            UserWeap.update({newUsername : WoodBat})
            UserArmor.update({newUsername : WoodenArmor})
            strUserWeap.update({newUsername : 'Wood Bat'})
            strUserArmor.update({newUsername : 'Wooden Armor'})
            UserPts.update({newUsername : 0})
            UserExtraDamage.update({newUsername : 1})
            UserAgility.update({newUsername : 1})
            UserGold.update({newUsername : 50})
            UserFloor.update({newUsername : 1})
            for x in UserLvlListings:
                x.update({newUsername : False})

            username = newUsername

    else:
        if string.lower(username) in signInListlower:
            usernameNum = signInListlower.index(lower(username))
            for k in singInList:
                if string.lower(k) == string.lower(username):
                    username = k
            password = input('Please type your password: ')
            if password == signInList[username]:
                print('Now return to Destination and confirm')
            else:
                print('Invalid Password')
                time.sleep(2)
                SignIn()
        else:
            print('Invalid Username')
            time.sleep(2)
            SignIn()
If you don't understand just tell me and I'll try to explain it more thoroughly.
Reply


Messages In This Thread
lowercasing to strings before comparison - by SheeppOSU - Apr-26-2019, 08:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to understand strings and lists of strings Konstantin23 2 821 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  Splitting strings in list of strings jesse68 3 1,824 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  What is wrong with this strings comparison minh 3 2,124 Jan-31-2020, 07:42 PM
Last Post: minh
  Finding multiple strings between the two same strings Slither 1 2,555 Jun-05-2019, 09:02 PM
Last Post: Yoriz
  lists, strings, and byte strings Skaperen 2 4,270 Mar-02-2018, 02:12 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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