Authenticating users with credentials stored in a database
In the previous recipe, we used a hard-coded set of username and password to verify the users' identity. In most real-world cases though, you will need to identify users and verify their identity using credentials that are stored in a database, or more specifically, in a table that holds user information.
Let's first create a table in the database that will hold user data.
Start the MySQL client, and after logging in, execute the following query in the phonebook database:
CREATE TABLE IF NOT EXISTS `users` ( `username` varchar(20) NOT NULL, `password` varchar(255) NOT NULL, PRIMARY KEY (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Now let's add a user to ...