Today, many websites feature a database of users. Viewers can register accounts required to access privileged areas of the website. For example, a clan could reserve pages on game tactics for members of the clan, rather than anyone and everyone who just might happen to come across their page.
This article will teach you how to create a simple user database using Zope objects for data storage rather than a relational database. You will learn how to create a registration system, a login system and a verification system to handle access to privileged pages. We will use Zope Page Templates and Python to do this.
First, we will build a registration system. Users will access the registration Zope Page Templates and fill out a form with their desired username and password. After submitting the form, the data will be handled by a Script ( Python ) object. The script will check to see if the username submitted already exists. If it doesn't, a file will be created with the user's username as the filename. A password property will be added to the file containing their hashed password.
A login system will then need to be built. Users will access the login Zope Page Template and enter their username and password in a form. When they submit the form, their username and password will be sent to a Script ( Python ) object, which will try it against the username's file. If the correct password is provided, two cookies will be set: a cookie containing the user's username and a cookie containing the user's hashed password.
When a user attempts to access a private page, the username and password provided in their cookies will be tried against the username's file. If the password matches, the user will be permitted to access the file.