Trying to spot what's wrong in the loop

krow:
I echoed what I read in and I actually get what I was expecting.

I don't believe you.

You have already told us that you are getting a spurious input which fails your 'password' check. The debug should have told you what the spurious input was. If it only shows what you expected then the problem you described cannot occur.