{"id":18772463,"url":"https://github.com/eftec/pdoone_login","last_synced_at":"2025-12-12T20:30:15.794Z","repository":{"id":71041803,"uuid":"253814088","full_name":"EFTEC/PdoOne_login","owner":"EFTEC","description":"It is a library","archived":false,"fork":false,"pushed_at":"2020-04-07T15:32:12.000Z","size":185,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-29T08:13:36.714Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.eftec.cl","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EFTEC.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-07T14:14:56.000Z","updated_at":"2024-09-23T21:03:58.000Z","dependencies_parsed_at":"2023-06-07T07:45:18.206Z","dependency_job_id":null,"html_url":"https://github.com/EFTEC/PdoOne_login","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2FPdoOne_login","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2FPdoOne_login/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2FPdoOne_login/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2FPdoOne_login/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EFTEC","download_url":"https://codeload.github.com/EFTEC/PdoOne_login/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239680815,"owners_count":19679505,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T19:29:10.478Z","updated_at":"2025-12-12T20:30:15.413Z","avatar_url":"https://github.com/EFTEC.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PdoOne_login\nAn example of a login page using php and mysql\n\nThis 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).\n\n![](img/img1.jpg)\n\n![](img/img2.jpg)\n\n## Initializing the project using composer\n\nRun composer as follow\n\n```composer init```\n\nThen, add your information and add the next dependencies: eftec/pdoone,  eftec/bladeone, eftec/validationone  \n\n* eftec/pdoone connects to the database\n\n* eftec/bladeone renders the view\n\n* eftec/validationone validates the user input. It's also a message container.\n\n\n\n\n```composer init\n\n\n  Welcome to the Composer config generator\n\n\n\nThis command will guide you through creating your composer.json config.\n\nPackage name (\u003cvendor\u003e/\u003cname\u003e) [jorge/pdo-one_login]: eftec/pdoone_login\nDescription []: example of a login page\nAuthor [\u003c\u003e, n to skip]:\nMinimum Stability []:\nPackage Type (e.g. library, project, metapackage, composer-plugin) []: project\nLicense []: mit\n\nDefine your dependencies.\n\nWould you like to define your dependencies (require) interactively [yes]?\nSearch for a package: eftec/pdoone\nEnter the version constraint to require (or leave blank to use the latest version):\nUsing version ^1.28 for eftec/pdoone\nSearch for a package: eftec/bladeone\nEnter the version constraint to require (or leave blank to use the latest version):\nUsing version ^3.37 for eftec/bladeone\nSearch for a package: eftec/validationone\nEnter the version constraint to require (or leave blank to use the latest version):\nUsing version ^1.23 for eftec/validationone\nSearch for a package:\nWould you like to define your dev dependencies (require-dev) interactively [yes]? no\n\n{\n    \"name\": \"eftec/pdoone_login\",\n    \"description\": \"example of a login page\",\n    \"type\": \"project\",\n    \"require\": {\n        \"eftec/pdoone\": \"^1.28\",\n        \"eftec/bladeone\": \"^3.37\",\n        \"eftec/validationone\": \"^1.23\"\n    },\n    \"license\": \"mit\",\n    \"authors\": [\n        {\n            \"name\": \"\",\n            \"email\": \"\"\n        }\n    ]\n}\n\nDo you confirm generation [yes]?\n```\n\n## Edit composer.json\n\nWe need to add a default namespace for psr-4. Add the next content inside composer.json\n\n```json\n\"autoload\": {\n    \"psr-4\": {\"PdoOne_login\\\\\": \"\"}\n},\n```\n\nAnd runs the next command\n\n```composer dump-autoload```\n\nTo rebuild the autoload\n\n## Creating the mysql table\n\n```sql\nCREATE TABLE `user` (\n  `userid` VARCHAR(50) NOT NULL,\n  `password` VARCHAR(60) NULL,\n  `fullname` VARCHAR(45) NULL,\n  PRIMARY KEY (`userid`));\n```\n\n## Generating the class Repo\n\nNo, we want to generate the class repository. [repo/UserRepo.php](repo/UserRepo.php) using PdoOne\n\n```shell script\nphp vendor/eftec/pdoone/lib/PdoOne.php -database mysql -server 127.0.0.1 -user root -pwd abc.123 -db testdb -input \"user\" -output classcode\n```\n\nThis 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.\n\nCopy the code and save it inside a new code in a new folder folder called repo\n\n📁 repo\n\n​     📝 UserRepo.php\n\n\n\n## Finishing the Class Repo\n\nWhile the class is complete but it misses a line, the namespace, so let's add the namespace to the class\n\n```php\nnamespace PdoOne_login\\repo;\n```\n\nwhy **PdoOne_login**?  It is because psr-4 (the line added in composer.json)\n\nAnd **why repo**? It is because the folder is called **repo**.\n\n\n\n## Creating the views\n\n📁 views\n\n​     📝 login.blade.php   login template\n\n​     📝 start.blade.php   start template (when we load)\n\nI used the html code form https://bootsnipp.com/tags/login\n\nI edited a bit and here, then I added the notation of Bladeone (check the library for more information)\n\n## Boilerplate code\n\n📁 app\n\n​     📝 app.php  it is our common file\n\n```php\n\u003c?php\n@session_start();\n\nuse eftec\\bladeone\\BladeOne;\nuse eftec\\PdoOne;\nuse eftec\\ValidationOne;\n\ninclude __DIR__.\"/../vendor/autoload.php\";\n\n\n// singleton and container\n\n/** @var BladeOne $bladeOne */\n$bladeOne=null;\n/** @var PdoOne $pdoOne */\n$pdoOne=null;\n/** @var ValidationOne $validationOne */\n$validationOne=null;\n\nfunction bladeOne() {\n    global $bladeOne;\n    if($bladeOne===null) {\n        $bladeOne=new BladeOne();\n    }\n    return $bladeOne;\n}\nfunction pdoOne() {\n    global $pdoOne;\n    if($pdoOne===null) {\n        $pdoOne=new PdoOne('mysql','127.0.0.1','root','abc.123','testdb');\n        $pdoOne-\u003elogLevel=3; // it shows all errors.\n        $pdoOne-\u003eopen();\n    }\n    return $pdoOne;\n}\nfunction validationOne() {\n    global $validationOne;\n    if($validationOne===null) {\n        $validationOne=new ValidationOne();\n    }\n    return $validationOne;\n}\n```\n\nWhat does it do?\n\nIt creates the instance of PdoOne (database), ValidationOne (validation and message container) and BladeOne (template)\n\nIt also starts a new session and enable the composer's autoloader.\n\nThe functions are quite simple. The work as : \n\n* If the variable is not defined, then it is created and initialized.\n\n* And the variable is returned.\n\n  \n\n## Our login code\n\n📝 index.php  it is our login code\n\n\n\n```\n\u003c?php\n\nuse PdoOne_login\\repo\\UserRepo;\n\ninclude \"app/app.php\";\n\n$buttonlogin=validationOne()-\u003etype('string')-\u003edef(false)-\u003epost('buttonlogin');\nif($buttonlogin===false) {\n    $login='';\n    $password='';\n} else {\n    $login=validationOne()-\u003etype('string')\n        -\u003econdition('minlen','The login must have at least 3 characters',3)\n        -\u003econdition('maxlen','The login must have at most 10 characters',10)\n        -\u003epost('login');\n    $password=validationOne()-\u003etype('string')\n        -\u003econdition('minlen','The password must have at least 3 characters',3)\n        -\u003epost('password');\n\n    if(validationOne()-\u003emessageList-\u003eerrorcount===0) {\n        $userDB= UserRepo::get($login);\n        if($userDB===null || $userDB===false || $userDB['password']!=$password) {\n            validationOne()-\u003emessageList-\u003eaddItem('general','User or password incorrect','error');\n        } else {\n            $_SESSION['user']=$userDB;\n            session_write_close(); \n            header('location:start.php',true);\n            die(1);\n        }\n    }\n}\n\necho bladeOne()-\u003erun('login'\n    ,['login'=\u003e$login,\n        'password'=\u003e$password]);\n```\n\nIt works as follow\n\n* if **buttonlogin** is false (not pressed) then\n  * It sets some default values (empty user and password)\n* If **buttonlogin** is not false then\n  * It reads the user and password.\n  * If it not fails (it could fail if the user has less than 3 characters or other conditions )\n    * We read from the database. We use the **UserRepo** class to read using the primary key.\n      * If the user (from the database) is false or if the password (read from the database) is not equals to the input password then\n        * It adds an error\n      * Otherwise\n        * It stores the user in the session\n        * Redirect to the login page\n* Finally, it shows the template using the library **BladeOne**\n\n## Final testing\n\nWe should not forget to add a new user into the database.\n\nLogin into our webserver and so we could test it.\n\n![](img/img1.jpg)\n\n\n\n## Security\n\nThe password is not hash-ed into the database.\n\nHow to hash it?\n\nChange the code\n\n```\n$userDB['password']!=$password\n```\n\nas\n\n```$userDB['password']!= hash('sha256', $password.$SALT)```\n\nwhere $SALT is a secret value defined in app.php\n\n`$SALT='asdk sk padk se4'3485'4385'¡4reorekkhptrkhptrkhk trhyktrpkptrkh+d+';// It is an example` \n\nThe value must be also store hashed in the database.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feftec%2Fpdoone_login","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feftec%2Fpdoone_login","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feftec%2Fpdoone_login/lists"}