Q:

Incorrect print statement for username/password program

def login():
    UserName = input("Please enter your username: ")
    passw = input("Please enter your password: ")
    check(UserName, passw)
    if check(UserName, passw) == True:
        print("Thank you for logging in.  Please enjoy these lyrics")
    else:
        print("Sorry, either your username or password is incorrect")

def check(UserName, passw):
    pword = {}
    for line in open('unames_passwords.txt','r'):
        user, password = line.split()
        pword[user] = password
        if user == UserName and password == passw:
            return True
        else:
            return False

def main():
    login()

The issue I'm having with my current code is, it prints the if True, print statement only if I enter the first name and password that is contained in a file, but if I enter any other name and password within the same file, it always prints the statement issued under else.  Anyone know what I've done wrong? 

A:

You return from check() based solely on the first line of the password file.  If the first password does not match, you return False immediately. 
Move return False out of the loop, so that it is only executed when you have scanned the whole file:
def check(UserName, passw):
    for line in open('unames_passwords.txt','r'):
        user, password = line.split()
        if user == UserName and password == passw:
            return True

    return False

I removed the pword dictionary handling here; your code doesn't actually make use of it. 
You probably want to avoid calling check() twice every login, and you don't have to test for == True; the if statement already tests that for you:
def login():
    UserName = input("Please enter your username: ")
    passw = input("Please enter your password: ")
    if check(UserName, passw):
        print("Thank you for logging in.  Please enjoy these lyrics")
    else:
        print("Sorry, either your username or password is incorrect")

