python - Simple password check TypeError: 'NoneType' object has no attribute '__getitem__' -
i'm getting error , highlighted code passw[0]
what error mean exactly? it's simple comparison since returned tuple can't compare it. need change password tuple? or have other way around come out equal? here's full code. it's simple password check.
def check_login(db, useremail, password): """returns true if password matches stored""" cur = db.cursor() password1 = db.crypt(password) ur = "select email users email = ?" cur.execute(ur, (useremail,)) user = cur.fetchone() if user[0] == useremail: pas = "select password users email = ? , password = ?" cur.execute(pas, (useremail, password1,)) passw = cur.fetchone() if passw[0] == password1: return true else: return false
passw = cur.fetchone()
cur.fetchone()
returns none
when there in no match. since you're taking password user, , looking , email, if passwords don't match, won't find row. result, cur.fetchone()
returns none. in fact, this:
passw = cur.fetchone() if passw[0] == password1: return true else: return false
can turn into:
return if cur.fetchone() not none: return true return false
or jen-ya suggested:
return cur.fetchone() not none
Comments
Post a Comment