After the instruction at line 29 you miss the instruction that checks if there are rows in your resultset and eventually moves to the first row.
I mean:
You must make this check before getting the coulmn values, i.e. at or before line 37
I suggest you skip the database connection and query if the username and/or password is null or empty. If you end up at line 32 you will have gone to the database for nothing.