How to use ion_auth in codeigniter??

hey folks, wanna need auth to your codeigniter applications?? its very easy which can be done in few steps:

1. Download Codeigniter and ion_auth

2. Copy all respective ion_auth files to your application directory folders like Ion_auth/config/ion_auth.php to system/application/config/ion_auth.php.

3. Create a database in mysql and execute the following queries in SQL.

CREATE TABLE `users` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`group_id` mediumint(8) unsigned NOT NULL,
`ip_address` char(16) NOT NULL,
`username` varchar(15) NOT NULL,
`password` varchar(40) 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,
`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,
PRIMARY KEY (`id`)
);
#
# Dumping data for table ‘users’
#

INSERT INTO `users` (`id`, `group_id`, `ip_address`, `username`, `password`, `salt`, `email`, `activation_code`, `forgotten_password_code`, `created_on`, `last_login`, `active`) VALUES
(‘1′,’1′,’127.0.0.1′,’administrator’,’59beecdf7fc966e2f17fd8f65a4a9aeb09d4a3d4′,’9462e8eee0′,’admin@admin.com’,”,NULL,’1268889823′,’1268889823′,’1′);

#########################################################################

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`)
);

#
# 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` mediumint(8) 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`)
);
#
# 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` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`user_id` mediumint(8) unsigned NOT NULL,
`group_id` mediumint(8) unsigned NOT NULL,
PRIMARY KEY (`id`)
);

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` mediumint(8) 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`)
);

4. Now goto applications->config->

autoload.php : $autoload[‘libraries’] = array(‘database’,’session’,’ion_auth’);

$autoload[‘helper’] = array(‘url’,’form’);

database.php: Add database name and username of database.

routes.php:  Change default controller to auth i.e.,$route[‘default_controller’] = “auth”;

config.php:  Add base_url and encryption key

Thats it now run your application with your url..

username: admin@admin.com

password: password

Advertisements