Recommend this page to a friend! |
Download |
Info | Example | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not yet rated by the users | Total: 173 | All time: 8,801 This week: 455 |
Version | License | PHP version | Categories | |||
pdoone_login 1.0 | GNU Lesser Genera... | 5 | PHP 5, Databases, User Management |
Description | Author | |
This package can authenticate users with records on MySQL using PDO. |
<?php |
An example of a login page using php and mysql
This example code implements a login page that validates the user into the database. It is a basic example and it lacks some features (such as hash of the password).
![](img/img1.jpg)
![](img/img2.jpg)
Run composer as follow
Then, add your information and add the next dependencies: eftec/pdoone, eftec/bladeone, eftec/validationone
* eftec/pdoone connects to the database
* eftec/bladeone renders the view
* eftec/validationone validates the user input. It's also a message container.
Welcome to the Composer config generator
This command will guide you through creating your composer.json config.
Package name (<vendor>/<name>) [jorge/pdo-one_login]: eftec/pdoone_login Description []: example of a login page Author [<>, n to skip]: Minimum Stability []: Package Type (e.g. library, project, metapackage, composer-plugin) []: project License []: mit
Define your dependencies.
Would you like to define your dependencies (require) interactively [yes]? Search for a package: eftec/pdoone Enter the version constraint to require (or leave blank to use the latest version): Using version ^1.28 for eftec/pdoone Search for a package: eftec/bladeone Enter the version constraint to require (or leave blank to use the latest version): Using version ^3.37 for eftec/bladeone Search for a package: eftec/validationone Enter the version constraint to require (or leave blank to use the latest version): Using version ^1.23 for eftec/validationone Search for a package: Would you like to define your dev dependencies (require-dev) interactively [yes]? no
{
"name": "eftec/pdoone_login",
"description": "example of a login page",
"type": "project",
"require": {
"eftec/pdoone": "^1.28",
"eftec/bladeone": "^3.37",
"eftec/validationone": "^1.23"
},
"license": "mit",
"authors": [
{
"name": "",
"email": ""
}
]
}
Do you confirm generation [yes]?
## Edit composer.json
We need to add a default namespace for psr-4. Add the next content inside composer.json
"autoload": {
"psr-4": {"PdoOne_login\\": ""}
},
And runs the next command
To rebuild the autoload
CREATE TABLE `user` (
`userid` VARCHAR(50) NOT NULL,
`password` VARCHAR(60) NULL,
`fullname` VARCHAR(45) NULL,
PRIMARY KEY (`userid`));
No, we want to generate the class repository. repo/UserRepo.php using PdoOne
php vendor/eftec/pdoone/lib/PdoOne.php -database mysql -server 127.0.0.1 -user root -pwd abc.123 -db testdb -input "user" -output classcode
This connects to a mysql database located in the server 127.0.0.1, user root, password abc.123, database testdb and table "user" (table created in the previous step). It will generate the whole class.
Copy the code and save it inside a new code in a new folder folder called repo
? repo
? ? UserRepo.php
While the class is complete but it misses a line, the namespace, so let's add the namespace to the class
namespace PdoOne_login\repo;
why PdoOne_login? It is because psr-4 (the line added in composer.json)
And why repo? It is because the folder is called repo.
? views
? ? login.blade.php login template
? ? start.blade.php start template (when we load)
I used the html code form https://bootsnipp.com/tags/login
I edited a bit and here, then I added the notation of Bladeone (check the library for more information)
? app
? ? app.php it is our common file
<?php
@session_start();
use eftec\bladeone\BladeOne;
use eftec\PdoOne;
use eftec\ValidationOne;
include __DIR__."/../vendor/autoload.php";
// singleton and container
/ @var BladeOne $bladeOne */
$bladeOne=null;
/ @var PdoOne $pdoOne */
$pdoOne=null;
/ @var ValidationOne $validationOne */
$validationOne=null;
function bladeOne() {
global $bladeOne;
if($bladeOne===null) {
$bladeOne=new BladeOne();
}
return $bladeOne;
}
function pdoOne() {
global $pdoOne;
if($pdoOne===null) {
$pdoOne=new PdoOne('mysql','127.0.0.1','root','abc.123','testdb');
$pdoOne->logLevel=3; // it shows all errors.
$pdoOne->open();
}
return $pdoOne;
}
function validationOne() {
global $validationOne;
if($validationOne===null) {
$validationOne=new ValidationOne();
}
return $validationOne;
}
What does it do?
It creates the instance of PdoOne (database), ValidationOne (validation and message container) and BladeOne (template)
It also starts a new session and enable the composer's autoloader.
The functions are quite simple. The work as :
? index.php it is our login code
<?php
use PdoOne_login\repo\UserRepo;
include "app/app.php";
$buttonlogin=validationOne()->type('string')->def(false)->post('buttonlogin');
if($buttonlogin===false) {
$login='';
$password='';
} else {
$login=validationOne()->type('string')
->condition('minlen','The login must have at least 3 characters',3)
->condition('maxlen','The login must have at most 10 characters',10)
->post('login');
$password=validationOne()->type('string')
->condition('minlen','The password must have at least 3 characters',3)
->post('password');
if(validationOne()->messageList->errorcount===0) {
$userDB= UserRepo::get($login);
if($userDB===null || $userDB===false || $userDB['password']!=$password) {
validationOne()->messageList->addItem('general','User or password incorrect','error');
} else {
$_SESSION['user']=$userDB;
session_write_close();
header('location:start.php',true);
die(1);
}
}
}
echo bladeOne()->run('login'
,['login'=>$login,
'password'=>$password]);
It works as follow
We should not forget to add a new user into the database.
Login into our webserver and so we could test it.
![](img/img1.jpg)
The password is not hash-ed into the database.
How to hash it?
Change the code
$userDB['password']!=$password
as
where $SALT is a secret value defined in app.php
`$SALT='asdk sk padk se4'3485'4385'¡4reorekkhptrkhptrkhk trhyktrpkptrkh+d+';// It is an example`
The value must be also store hashed in the database.
Files (58) |
File | Role | Description | ||
---|---|---|---|---|
app (1 file) | ||||
compiles (2 files) | ||||
css (1 file) | ||||
img (2 files) | ||||
repo (1 file) | ||||
vendor (1 file, 2 directories) | ||||
views (2 files) | ||||
composer.json | Data | Auxiliary data | ||
composer.lock | Data | Auxiliary data | ||
index.php | Example | Example script | ||
LICENSE | Lic. | License text | ||
logout.php | Aux. | Auxiliary script | ||
README.md | Doc. | Read me | ||
start.php | Example | Example script |
Files (58) | / | compiles |
File | Role | Description |
---|---|---|
2736fab291f04e69b6...361f5b82461a.bladec | Example | Example script |
2b020927d3c6eb4072...ce3597a3f88d.bladec | Example | Example script |
Files (58) | / | vendor |
File | Role | Description | ||
---|---|---|---|---|
composer (8 files) | ||||
eftec (3 directories) | ||||
autoload.php | Aux. | Auxiliary script |
Files (58) | / | vendor | / | composer |
File | Role | Description |
---|---|---|
autoload_classmap.php | Aux. | Auxiliary script |
autoload_namespaces.php | Aux. | Auxiliary script |
autoload_psr4.php | Aux. | Auxiliary script |
autoload_real.php | Class | Class source |
autoload_static.php | Class | Class source |
ClassLoader.php | Class | Class source |
installed.json | Data | Auxiliary data |
LICENSE | Lic. | License text |
Files (58) | / | vendor | / | eftec |
File | Role | Description | ||
---|---|---|---|---|
bladeone (10 files, 1 directory) | ||||
pdoone (4 files, 1 directory) | ||||
validationone (3 files, 1 directory) |
Files (58) | / | vendor | / | eftec | / | bladeone |
File | Role | Description | ||
---|---|---|---|---|
lib (8 files) | ||||
.php_cs | Example | Example script | ||
BladeOneCache.md | Data | Auxiliary data | ||
BladeOneHtml.md | Data | Auxiliary data | ||
BladeOneLang.md | Data | Auxiliary data | ||
BladeOneLogic.md | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpcs.xml | Data | Auxiliary data | ||
README.md | Example | Example script | ||
readme.template.md | Doc. | Documentation |
Files (58) | / | vendor | / | eftec | / | bladeone | / | lib |
File | Role | Description |
---|---|---|
BladeOne.php | Class | Class source |
BladeOneCache.php | Class | Class source |
BladeOneCacheRedis.php | Class | Class source |
BladeOneCustom.php | Class | Class source |
BladeOneHtml.php | Class | Class source |
BladeOneHtml2.php | Class | Class source |
BladeOneHtmlBootstrap.php | Class | Class source |
BladeOneLang.php | Class | Class source |
Files (58) | / | vendor | / | eftec | / | pdoone |
File | Role | Description | ||
---|---|---|---|---|
lib (3 files) | ||||
autoload.php | Aux. | Auxiliary script | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Documentation |
Files (58) | / | vendor | / | eftec | / | pdoone | / | lib |
File | Role | Description |
---|---|---|
IPdoOneCache.php | Class | Class source |
PdoOne.php | Class | Class source |
PdoOneEncryption.php | Class | Class source |
Files (58) | / | vendor | / | eftec | / | validationone |
File | Role | Description | ||
---|---|---|---|---|
lib (5 files) | ||||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Documentation |
Files (58) | / | vendor | / | eftec | / | validationone | / | lib |
File | Role | Description |
---|---|---|
MessageItem.php | Class | Class source |
MessageList.php | Class | Class source |
ValidationInputOne.php | Class | Class source |
ValidationItem.php | Class | Class source |
ValidationOne.php | Class | Class source |
Files (58) | / | views |
File | Role | Description |
---|---|---|
login.blade.php | Aux. | Auxiliary script |
start.blade.php | Aux. | Auxiliary script |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.