In this chapter, we will implement a new authentication system in order to allow administrators of the newsletter to be authenticated. Since PHP5, PHP has improved and added a feature that object-oriented developers have used to separate namespaces.
Let's start by defining a namespace named Newsletter
as follows:
<?php namespace Newsletter; //this must always be in every class that will use namespaces class Authentication { } ?>
In the preceding example, our Newsletter
namespace will have an Authentication
class. When other classes or PHP scripts need to use Newsletter
's Authentication
class, they can simple declare it using the following code:
Use Newsletter\Authentication;
Inside our Newsletter
class, let's create a simple check for the user using bcrypt, which is a popular and secure way of creating and storing hashed passwords.