Your code is impressive. I also did the similar stuff but your is much better.
By the way, you still have some issue that your input text cannot handle symbols. My AP setup contain symbol in the password and I believe that many people also put symbol in the password too.
Waiting for your improve.