CT 310 Lecture 15 Authentication Example

The examples here illustrate a series of important steps. The first example is retained in part for legacy reasons; it shows how to write PHP code that moves user data easily between a Tab Separated Varaible file format and an array of obejcts in PHP. Students in CT 310 Spring 2016 may largely ignore this example.

The second example is a much like the first, but involves less code in the support file because it uses the more recent CSV file reading and writing capabiltiies of PHP. The second example also users a more up-to-date (not md5) password hashing and verification mechanism.

Both examples, because they store persistent data in a simple file rather than a database, represent a first step toward the use of databases. This simple technique of storing data in spreadsheet files should be considered when:

  1. A user may wish to edit persistent data in a spreadsheet program.
  2. The amount of persistant data is small and fits easily in a single table.

Note also the heavy use of the PHP header commandin Example 2 in order that the contents of the tiny site is protected until a user successfully logs into the site.

The above examples have the drawback that you cannot see the actual PHP code, so they can be downloaded as a zip file.

Note the second example includes a backwards compatible addition for PHP versions 5.3 and 5.4. See the phpPasswordHashingLib documentation for additional information.