Unless you're required to code it yourself, there is a very good tutorial and explanation on how to use the built in features for login here:
kvprajapati commented: Good suggestion. +7
Ezzaral commented: That's because you actually have enough initiative to try to learn on your own and think for yourself :) +18
bajanpoet commented: great help! Stuck with all my fumbles and mistakes till I figured out how to get my code to work. +3
Ramy Mahrous commented: Helps well! +6
Comatose commented: When Will They Learn? +9
ddanbe commented: At least I am not alone! +4
Comatose commented: Perfect Code Port +8
Salem commented: Quite so, quite so. +21
bpacheco1227 commented: a great help +2