Authentication rewrited from the book