This code does have some flaws, it is meant for explaining the concept to someone starting out. I'll be writing a series of articles on production grade authentication which is going to cover everything in depth with the latest tools and patterns, stay tuned!