CI4 User Authentication System |
This is a great idea as I haven't found anything great out there during a recent search. I don't have migrations set up, but have a look at what I've done in Ignition Go for CI3... I'm pasting the SQL table structure below. This structure has given me many great years of use... I won't take credit for creating it though, it came from CI Bonfire. In Ignition Go (and/or Bonfire) you will also find roles and permissions tables to go along with these.
What would be really cool would be to make a multi-framework PSR4 library that would work for either CI4, Laravel5, or Symfony. # # TABLE STRUCTURE FOR: user / login related # # login attempt tracking CREATE TABLE IF NOT EXISTS `igo_login_attempts` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `ip_address` varchar(45) NOT NULL, `login` varchar(255) NOT NULL, `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; # user CREATE TABLE IF NOT EXISTS `igo_users` ( `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, `role` enum('admin','staff','user','support') NOT NULL DEFAULT 'user', `email` varchar(254) NOT NULL, `username` varchar(30) NOT NULL DEFAULT '', `first_name` varchar(50) DEFAULT NULL, `last_name` varchar(50) DEFAULT NULL, `password_hash` char(255) DEFAULT NULL, `reset_hash` varchar(40) DEFAULT NULL, `last_login` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `last_ip` varchar(45) NOT NULL DEFAULT '', `force_password_reset` tinyint(1) DEFAULT '0', `reset_by` int(10) DEFAULT NULL, `banned` tinyint(1) NOT NULL DEFAULT '0', `ban_message` varchar(255) DEFAULT NULL, `display_name` varchar(255) DEFAULT '', `display_name_changed` date DEFAULT NULL, `timezone` varchar(40) NOT NULL DEFAULT 'UM6', `language` varchar(20) NOT NULL DEFAULT 'english', `active` tinyint(1) NOT NULL DEFAULT '0', `activate_hash` varchar(40) NOT NULL DEFAULT '', `created_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `modified_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `deleted` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `email` (`email`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; INSERT INTO `igo_users` (`id`, `role`, `email`, `username`, `password_hash`, `reset_hash`, `last_login`, `last_ip`, `created_on`, `deleted`, `reset_by`, `banned`, `ban_message`, `display_name`, `display_name_changed`, `timezone`, `language`, `active`, `activate_hash`, `force_password_reset`) VALUES (1, 'admin', '[email protected]', 'admin', '$2a$08$T/79zwGVEtodc2Sop8XPReTrv0WviLcFt1Zp3d3ywlAuVCrmsTszi', NULL, '0000-00-00 00:00:00', '', now(), 0, NULL, 0, NULL, 'admin', NULL, 'UM6', 'english', 1, '', 0); # cookies CREATE TABLE IF NOT EXISTS `igo_user_cookies` ( `user_id` bigint(20) UNSIGNED NOT NULL, `token` varchar(128) NOT NULL, `created_on` datetime NOT NULL, KEY `token` (`token`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; # user meta data CREATE TABLE IF NOT EXISTS `igo_user_meta` ( `meta_id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, `user_id` bigint(20) UNSIGNED NOT NULL DEFAULT '0', `meta_key` varchar(255) NOT NULL DEFAULT '', `meta_value` text, PRIMARY KEY (`meta_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; I recently also ran across an interesting library called Gatekeeper: https://github.com/psecio/gatekeeper What I like is this is just the backend pieces, separate from the screens. I was actually going to build some screens to go with it. Hope this all helps, Bob Join Codeigniter Slack Chat
Sign up for Codeigniter Slack Chat
|
Welcome Guest, Not a member yet? Register Sign In |