This class can register and login users in a database with PDO. It can:
A Secure PHP7 class for basic user login and registration.
Very easy to use as REST API, with AJAX and Bootstrap
PHP Tested: 5.6.19, 7.0.11
This PHP Secure Login class is available in the PHP Classes site
1. VARIABLE DEFINITIONS
2. ALL METHODS
2.1. User::dbConnect()
2.2. User::getUser()
2.3. User::login()
2.4. User::registration()
2.5. User::sendConfirmationEmail()
2.6. User::emailActivation()
2.7. User::passwordChange()
2.8. User::assignRole()
2.9. User::userUpdate()
2.10. User::checkEmail()
2.11. User::registerWrongLoginAttemp()
2.12. User::hashPass()
2.13. User::printMsg()
2.14. User::logout()
2.15. User::listUsers()
2.16. User::render()
2.17. User::indexHead(), User::indexTop(), User::loginForm(), User::activationForm(), User::indexMiddle(), User::registerForm(), User::indexFooter(), User::userPage()
Variable definitions provided in the beginning of the class:
/** @var object $pdo Copy of PDO connection */
private $pdo;
/** @var object of the logged in user */
private $user;
/** @var string error msg */
private $msg;
/** @var int number of permitted wrong login attemps */
private $permitedAttemps = 5;
Connection init function.
$conString DB connection string. $user DB user. $pass DB password.
Return the logged in user.
Login function.
$email User email. $password User password.
Register a new user account function
$email User email. $fname User first name. $lname User last name. $pass User password.
Email the confirmation code function.
$email User email.
Activate a login by a confirmation code function.
$email User email. $confCode Confirmation code.
Password change function.
$id User id. $pass New password.
Assign a role function.
$id User id. $role User role.
User information change function.
$id User id. $fname User first name. $lname User last name.
Check if email is already used function.
$email User email.
Register a wrong login attemp function.
$email User email.
Password hash function.
$password User password.
Print error msg function.
Logout the user and remove it from the session.
Returns an array of all available users in the DB.
Simple template rendering function $path path of the template file.
Template functions depending on a config file to show different parts of HTML in the examples.