An example of authentication system for your website.
It is written in objective PHP which uses MySQLi instead of PDO.
authBase is using a PHPMailer-5.2-stable version, documentation here: PHPMailer.
Some files contains a ready PHPMailer function which is prepared to send
Files in authBase are predicted to use AJAX or jQuery.
It can be easily used with sweetAlert2 library for fancy alerts.
Feel free to use it :)
The authBase contains files:
config.php
login.php
registration.php
verify.php
lostPassword.php
passRenew.php
passRenewWork.php
Most of the files are strictly connected to each other while others work independetly.
-
config.php
is used in every file. -
login.php
is not related with any other file thanconfig.php
. -
registration.php
sends an email to user with link toverify.php
. -
lostPassword.php
sends an email to user with link topassRenew.php
and this file is strictly connected withpassRenewWork.php
- AJAX recommended here.
This file contains:
<?php
$dbserver = "";
$dbuser = "";
$dbpass = "";
$dbname = "";
$link = new mysqli($dbserver, $dbuser, $dbpass, $dbname);
if ($link->connect_error) {
die("Connection failed: " . $link->connect_error);
}
$serwer_smtp = "";
$port_smtp = 465;
$smtplog = '';
$smtppass = '';
?>
-
To connect to your database you must fill 4 first lines with suitable data.
-
$serwer_smtp
- (SMTP Server/Host) and$port_smtp
are used in PHPMailer. Fulfill with suitable data. -
$smtplog
- (email) and$smtppass
are used to connect to sender email.
My example table users
look like this:
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT;
`username` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`hash` varchar(255) NOT NULL,
`active` int(1) NOT NULL DEFAULT 0,
`usertype` varchar(255) NOT NULL DEFAULT 'normal'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `users`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `username` (`username`),
ADD UNIQUE KEY `email` (`email`);
COMMIT;
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
You can contact me via email: adrian.goral@gmail.com