Amazon Best Products with minimum price

Wednesday 5 April 2017

Integrate Ion-auth Authentication and Roles in Codeigniter Framework

Ion-Auth is a Library which manage Roles and authentication of the User in codeigniter framework.

In this Tutorial, we are going to learn how to integrate Ion-Auth Library in codeigniter framework.This Library is great, it has group of User Table , Roles table, login attempt to failure table and CSRF which avoids "form" from Internal attack.

Here are the following steps which we should follow to integrate the Ion-Auth Library into Codeigniter framework.



1) Install the Codeigniter Framework.

Go to the Website of Codeigniter and download the codeigniter, There are two version available (version 2 and version 3). Always download the latest version (i.e.Version 3) because latest version has more features, thereby download and save the zip file in your computer and Extract it in root directory, c:\xampp\htdocs. After Extraction we can change the file name to whatever one want's.

2) Install the Ion-Auth.

Go to the repository in github and download the zip file of Ion-Auth library.

Once we are done with downloading, we will extract the zip file in folder and pass the necessary file to our respective project.

Which are:

a) Copy the file taht is config called ion_auth.php into config folder.
b) Copy the file that is in controller called auth.php into controller folder.
c) Copy the file that is in library Bycrypt.php and Ion_auth.php into library folder.
d) Copy the file that is in Model ion_auth_model.php into Model folder.
e) Copy the file that is in View ion_auth.php into view folder.

3) Database:

Now let's create the database in mysql called ion_auth and import the following tables.
These tables work on the following authentication and roles:

DROP TABLE IF EXISTS `groups`;

#
# Table structure for table 'groups'
#

CREATE TABLE `groups` (
  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(20) NOT NULL,
  `description` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

#
# Dumping data for table 'groups'
#

INSERT INTO `groups` (`id`, `name`, `description`) VALUES
     (1,'admin','Administrator'),
     (2,'members','General User');



DROP TABLE IF EXISTS `users`;

#
# Table structure for table 'users'
#

CREATE TABLE `users` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `ip_address` varbinary(16) NOT NULL,
  `username` varchar(100) NOT NULL,
  `password` varchar(80) NOT NULL,
  `salt` varchar(40) DEFAULT NULL,
  `email` varchar(100) NOT NULL,
  `activation_code` varchar(40) DEFAULT NULL,
  `forgotten_password_code` varchar(40) DEFAULT NULL,
  `forgotten_password_time` int(11) unsigned DEFAULT NULL,
  `remember_code` varchar(40) DEFAULT NULL,
  `created_on` int(11) unsigned NOT NULL,
  `last_login` int(11) unsigned DEFAULT NULL,
  `active` tinyint(1) unsigned DEFAULT NULL,
  `first_name` varchar(50) DEFAULT NULL,
  `last_name` varchar(50) DEFAULT NULL,
  `company` varchar(100) DEFAULT NULL,
  `phone` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


#
# Dumping data for table 'users'
#

INSERT INTO `users` (`id`, `ip_address`, `username`, `password`, `salt`, `email`, `activation_code`, `forgotten_password_code`, `created_on`, `last_login`, `active`, `first_name`, `last_name`, `company`, `phone`) VALUES
     ('1',0x7f000001,'administrator','59beecdf7fc966e2f17fd8f65a4a9aeb09d4a3d4','9462e8eee0','admin@admin.com','',NULL,'1268889823','1268889823','1', 'Admin','istrator','ADMIN','0');


DROP TABLE IF EXISTS `users_groups`;

#
# Table structure for table 'users_groups'
#

CREATE TABLE `users_groups` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` int(11) unsigned NOT NULL,
  `group_id` mediumint(8) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_users_groups_users1_idx` (`user_id`),
  KEY `fk_users_groups_groups1_idx` (`group_id`),
  CONSTRAINT `uc_users_groups` UNIQUE (`user_id`, `group_id`),
  CONSTRAINT `fk_users_groups_users1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION,
  CONSTRAINT `fk_users_groups_groups1` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `users_groups` (`id`, `user_id`, `group_id`) VALUES
     (1,1,1),
     (2,1,2);


DROP TABLE IF EXISTS `login_attempts`;

#
# Table structure for table 'login_attempts'
#

CREATE TABLE `login_attempts` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `ip_address` varbinary(16) NOT NULL,
  `login` varchar(100) NOT NULL,
  `time` int(11) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 These tables are very simple, see the description down:

a) user table: it stores all information of user like user_name, email_id, password, first_name, last_name etc.
b) login_attempt table: 1 to 1 with users, ip_address is foreign key.
c) Group table: Allow to create new group based on the group it assigns the role.
d) users_groups table: many to many between users and groups.

For running the program call the ion_auth.php file which is located in  application/controller folder.

I hope you can now easily integrate the Ion_Auth library int codeigniter framework.

If anyone has any issues, feel free to write in the comments down below.

Thank you
 


No comments:

Post a Comment