Registration / Login - Implementation in the KKK ================================================ This guide will give its reader an in-depth look at how KittoKittoKitto implements its registration/authentication system. Special attention will be paid to how the user's password is stored and communicated from the client to the server. For more background on the architecture of Kitto, see the [developer guide](http://modulargaming.com/projects/modulargaming/wiki/MgDevelop) maintained by the ModularGaming project. Database Schema --------------- The first thing we will need is a database table to hold our user in. The following _user_ table will be used for the remainder of this guide. It is the Kitto _user_ table with all fields unrelated to this tutorial removed. CREATE TABLE `user` ( -- User & password. `user_id` int(11) NOT NULL auto_increment, `user_name` varchar(25) NOT NULL, `password_hash` char(32) default NULL, `password_hash_salt` char(32) NOT NULL, -- Used for managing logins `current_salt` char(32) NOT NULL, `current_salt_expiration` datetime NOT NULL, -- Profile information `datetime_created` datetime default NULL, `email` text NOT NULL, `age` smallint(3) unsigned NOT NULL, `gender` enum('male','female') NOT NULL, `profile` text NOT NULL, `signature` text NOT NULL, -- Other useful information. `registered_ip_addr` varchar(16) default NULL, `last_ip_addr` varchar(16) default NULL, `last_activity` datetime default NULL, -- Password reset stuff. `password_reset_requested` datetime NOT NULL, `password_reset_confirm` varchar(32) NOT NULL, PRIMARY KEY (`user_id`), UNIQUE KEY `user_name` (`user_name`) ); Registration - Frontend ------------------------ We will need a way to get new users in to the _user_ table. This is achieved via the registration process. Our register page has several components: an HTML form that users fill out, bits of Javascript that assist the user in filling the form out correctly, a PHP script that validates the form, and more PHP that stores the user data in the database. We will begin with a look at [our HTML form](http://github.com/OwlManAtt/kittokittokitto/raw/fe93a820c16e52e9b23147e1a4edca3fae10a7d2/template/templates/user/register_form.tpl). The first line of interest is the form tag - it tells the user's browser where to send the form data (action) and using what HTTP method (method).