Welcome Guest, Not a member yet? Register   Sign In
CI4 User Authentication System
#8

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
Reply


Messages In This Thread
CI4 User Authentication System - by ajturner - 03-03-2017, 11:07 AM
RE: CI4 User Authentication System - by kilishan - 03-03-2017, 04:03 PM
RE: CI4 User Authentication System - by atishamte - 03-03-2017, 10:31 PM
RE: CI4 User Authentication System - by ajturner - 03-04-2017, 07:07 AM
RE: CI4 User Authentication System - by ajturner - 03-04-2017, 09:29 AM
RE: CI4 User Authentication System - by kierownik - 03-04-2017, 12:31 PM
RE: CI4 User Authentication System - by visualsol - 03-04-2017, 05:02 PM
RE: CI4 User Authentication System - by skunkbad - 03-04-2017, 06:40 PM
RE: CI4 User Authentication System - by PaulD - 03-04-2017, 08:30 PM
RE: CI4 User Authentication System - by Narf - 03-06-2017, 02:51 AM
RE: CI4 User Authentication System - by qury - 03-06-2017, 05:48 AM
RE: CI4 User Authentication System - by ajturner - 03-06-2017, 07:14 AM
RE: CI4 User Authentication System - by Narf - 03-06-2017, 07:41 AM
RE: CI4 User Authentication System - by ajturner - 03-06-2017, 08:15 AM
RE: CI4 User Authentication System - by qury - 03-06-2017, 10:25 AM
RE: CI4 User Authentication System - by cartalot - 03-06-2017, 11:13 AM
RE: CI4 User Authentication System - by qury - 03-06-2017, 11:50 AM
RE: CI4 User Authentication System - by skunkbad - 03-06-2017, 04:48 PM
RE: CI4 User Authentication System - by visualsol - 03-06-2017, 10:53 PM
RE: CI4 User Authentication System - by ajturner - 03-09-2017, 08:32 AM
RE: CI4 User Authentication System - by kilishan - 03-09-2017, 01:36 PM
RE: CI4 User Authentication System - by blaasvaer - 09-02-2020, 05:27 AM
RE: CI4 User Authentication System - by InsiteFX - 09-02-2020, 07:50 AM



Theme © iAndrew 2016 - Forum software by © MyBB