forked from benedmunds/CodeIgniter-Ion-Auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1539 lines (1333 loc) · 46 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ion Auth</title>
<style type='text/css' media='all'>@import url('./userguide.css');</style>
<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/functions.js"></script>
<meta http-equiv='expires' content='-1' />
<meta http-equiv= 'pragma' content='no-cache' />
<meta name='robots' content='all' />
</head>
<body>
<!-- START NAVIGATION -->
<div id="nav"><div id="nav_inner">
<table cellpadding="0" cellspacing="0" border="0" style="width:98%">
<tr>
<td class="td" valign="top">
<h3>Author Info</h3>
<ul>
<li><a href="http://benedmunds.com">Ben Edmunds</a></li>
<li><a href="https://github.com/benedmunds">GitHub</a></li>
</ul>
<h3>Basic Info</h3>
<ul>
<li><a href="#license">License</a></li>
<li><a href="https://github.com/benedmunds/CodeIgniter-Ion-Auth">GitHub Repo</a></li>
</ul>
<h3>Introduction</h3>
<ul>
<li><a href="#requirements">Server requirements</a></li>
<li><a href="#install">Installation</a></li>
<li><a href="#upgrade">Upgrading</a></li>
<li><a href="#loading">Loading the Library</a></li>
</ul>
</td>
<td class="td_sep" valign="top">
<h3>Configuration</h3>
<ul>
<li><a href="#use_config">Config Options</a></li>
</ul>
<h3>Class Functions</h3>
<ul>
<li><a href="#login">login()</a></li>
<li><a href="#logout">logout()</a></li>
<li><a href="#register">register()</a></li>
<li><a href="#create_user">create_user()</a></li>
<li><a href="#update">update()</a></li>
<li><a href="#update_user">update_user()</a></li>
<li><a href="#delete_user">delete_user()</a></li>
<li><a href="#forgotten_password">forgotten_password()</a></li>
<li><a href="#forgotten_password_check">forgotten_password_check()</a></li>
<li><a href="#logged_in">logged_in()</a></li>
<li><a href="#is_admin">is_admin()</a></li>
<li><a href="#in_group">in_group()</a></li>
<li><a href="#username_check">username_check()</a></li>
<li><a href="#email_check">email_check()</a></li>
<li><a href="#identity_check">identity_check()</a></li>
<li><a href="#is_max_login_attempts_exceeded">is_max_login_attempts_exceeded()</a></li>
<li><a href="#get_attempts_num">get_attempts_num()</a></li>
<li><a href="#increase_login_attempts">increase_login_attempts()</a></li>
<li><a href="#clear_login_attempts">clear_login_attempts()</a></li>
<li><a href="#user">user()</a></li>
<li><a href="#users">users()</a></li>
<li><a href="#group">group()</a></li>
<li><a href="#groups">groups()</a></li>
<li><a href="#get_users_groups">get_users_groups()</a></li>
<li><a href="#add_to_group">add_to_group()</a></li>
<li><a href="#remove_from_group">remove_from_group()</a></li>
<li><a href="#create_group">create_group()</a></li>
<li><a href="#update_group">update_group()</a></li>
<li><a href="#delete_group">delete_group()</a></li>
<li><a href="#messages">messages()</a></li>
<li><a href="#messages_array">messages_array()</a></li>
<li><a href="#set_message_delimiters">set_message_delimiters()</a></li>
<li><a href="#errors">errors()</a></li>
<li><a href="#errors_array">errors_array()</a></li>
<li><a href="#set_error_delimiters">set_error_delimiters()</a></li>
<li><a href="#trigger_events">trigger_events()</a></li>
<li><a href="#set_hook">set_hook()</a></li>
</ul>
</td>
</tr>
</table>
</div></div>
<div id="nav2"><a name="top"> </a><a href="#" id="toggle_toc"><img src="images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
<div id="masthead">
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td><h1>Documentation</h1></td>
<td id="breadcrumb_right">Author:<a href="http://benedmunds.com">Ben Edmunds</a></td>
</tr>
</table>
</div>
<!-- END NAVIGATION -->
<!-- START BREADCRUMB -->
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td id="breadcrumb">
<a href="http://benedmunds.com/ion_auth">Ion Auth</a> ›
Documentation
</td>
</tr>
</table>
<!-- END BREADCRUMB -->
<br clear="all" />
<!-- START CONTENT -->
<div id="content">
<h1>Ion Auth</h1>
<p>Ion Auth is a simple and lightweight authentication library for the CodeIgniter framework</p>
<a name="license"></a>
<h2>License</h2>
<p>Ion Auth is released under the Apache License v2.0. You can read the license here: <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">http://www.apache.org/licenses/LICENSE-2.0</a></p>
<a name="requirements"></a>
<h2>Server requirements</h2>
Ion Auth 3 needs <strong>CodeIgniter 3</strong> and <strong>PHP 5.6</strong>.<br/>
It should work on 5.3.7 as well, but we strongly advise you NOT to run such old versions of PHP,
because of potential security and performance issues.<br/>
If running an old PHP version, you may need
<a href="https://github.com/ircmaxell/password_compat" target="_blank">password_compat</a>.
<a name="install"></a>
<h2>Installation</h2>
<ol>
<li>
Download the latest version:
<a href="https://github.com/benedmunds/CodeIgniter-Ion-Auth/zipball/3">https://github.com/benedmunds/CodeIgniter-Ion-Auth/zipball/3</a>
</li>
<li>Copy the files from this package to the correspoding folder in your application folder. For example, copy Ion_auth/config/ion_auth.php to system/application/config/ion_auth.php.</li>
<li>You can also copy the entire directory structure into your third_party/ folder. For example, copy everything to /application/third_party/ion_auth/</li>
<li>Run the appropriate SQL file from the /sql directory.</li>
</ol>
<p>The default login is:</p>
<ul>
<li>Email: [email protected]</li>
<li>Password: password</li>
</ul>
<a name="upgrade"></a>
<h2>Upgrading</h2>
<ol>
<li>
Download the latest version:
<a href="https://github.com/benedmunds/CodeIgniter-Ion-Auth/zipball/3">https://github.com/benedmunds/CodeIgniter-Ion-Auth/zipball/3</a>
</li>
<li>Overwrite "libraries/ion_auth.php" and "models/ion_auth_model.php" with the new versions.</li>
<li>Overwrite "language/*" with the news versions.</li>
<li>Check "config/ion_auth.php" for evolution.</li>
</ol>
<p>
Upgrading from Ion Auth 2? Check the UPGRADING.md file in the package.
</p>
<a name="loading"></a>
<h2>Loading Ion Auth</h2>
<p>You load Ion Auth just like any other library:</p>
<pre>$this->load->library('ion_auth');</pre>
<p>Do make sure to load your database connection first, that can be loaded manually or autloaded.</p>
<p>You can also autoload the library.</p>
<a name="use_config"></a>
<h2>Configuration Options</h2>
<p>Ion Auth is extremely configurable.</p>
<p>To change configuration options simply edit the config/ion_auth.php file or pass an array when loading the library.</p>
<h3>Tables</h3>
<ul>
<li>
<strong>tables['groups']</strong> Default is 'groups'<br/>
The table name to use for the groups table.
</li>
<li>
<strong>tables['users']</strong> Default is 'users'<br/>
The table name to use for the users table.
</li>
<li>
<strong>tables['users_groups']</strong> Default is 'users_groups'<br/>
The table name to use for the users groups table.
</li>
<li>
<strong>tables['login_attempts']</strong> Default is 'login_attempts'<br/>
The table name to use for the login attempts table.
</li>
<li>
<strong>join['users'] </strong> Default is 'user_id'<br/>
Users table column you want to join WITH.
</li>
<li>
<strong>join['groups'] </strong> Default is 'group_id'<br/>
Group table column you want to join WITH.
</li>
</ul>
<h3>Hash method</h3>
<ul>
<li>
<strong>hash_method</strong> Default is 'bcrypt'<br/>
The method to hash the password before storing in database.
You can choose between bcrypt (from PHP 5.3) or argon2 (from PHP 7.2)<br/>
Argon2 is recommended by expert (it is actually the
<a href="https://password-hashing.net" target="_blank">winner of the Password Hashing Competition</a>).<br/>
Passwords are automatically salted before hashing (everything is stored in the same 'password' column).<br/>
For more information, check the
<a href="http://php.net/manual/en/function.password-hash.php" target="_blank">password_hash function help</a>.
</li>
<li><strong>Bcrypt-specific options:</strong><br/>
<ul>
<li>
<strong>bcrypt_default_cost</strong> Default is 10<br/>
This defines how strong the encryption will be.<br/>
However, higher the cost, longer it will take to hash (CPU usage).
So adjust this based on your server hardware.
</li>
<li>
<strong>bcrypt_admin_cost</strong> Default is 12<br/>
Same as bcrypt_default_cost, but for users in the admin group.<br/>
It is recommended to have a stronger hashing for administrators.
</li>
</ul>
You should benchmark your server to find the best cost value.
It is recommended to have a hash taking at least 100ms (500ms for administrators).<br/>
This can be done easily with this
<a href="https://gist.github.com/Indigo744/24062e07477e937a279bc97b378c3402" target="_blank">
little script for bcrypt
</a>.<br/>
It is not recommended (in 2018) to use a value less than 10.
</li>
<li><strong>Argon2-specific options:</strong><br/>
<ul>
<li>
<strong>argon2_default_params</strong> Default is ['memory_cost' => 1 << 12, 'time_cost' => 2, 'threads' => 2]<br/>
This is an array containing the options for the Argon2 algorithm. The following keys can be set: <br/>
<strong>['memory_cost']</strong>: Maximum memory (in kBytes) that may be used to compute the Argon2 hash.
The spec recommends setting the memory cost to a power of 2.<br/>
<strong>['time_cost']</strong>: Number of iterations (used to tune the running time independently of the memory size).
This defines how strong the encryption will be.<br/>
<strong>['threads']</strong>: Number of threads to use for computing the Argon2 hash.
The spec recommends setting the memory cost to a power of 2.
</li>
<li>
<strong>argon2_admin_params</strong> Default is ['memory_cost' => 1 << 14, 'time_cost' => 4, 'threads' => 2]<br/>
Same as argon2_default_params, but for users in the admin group.<br/>
It is recommended to have a stronger hashing for administrators.
</li>
</ul>
You should benchmark your server to find the best parameters.
It is recommended to have a hash taking at least 100ms (500ms for administrators).<br/>
This can be done easily with this
<a href="https://gist.github.com/Indigo744/e92356282eb808b94d08d9cc6e37884c" target="_blank">
little script for argon2
</a>.<br/>
The argon2 algorithm doesn't have <em>bad parameters</em> (even with time_cost at 1)
but remember that longer the hashing, stronger the security.
</li>
</ul>
<h3>Authentication options</h3>
<ul>
<li>
<strong>site_title</strong><br/>
The title of your site, used for email.
</li>
<li>
<strong>admin_email</strong> Default is '[email protected]'<br/>
Your administrator email address.
</li>
<li>
<strong>default_group</strong> Default is 'members'<br/>
Name of the default user group.
</li>
<li>
<strong>admin_group</strong> Default is 'admin'<br/>
Name of the admin group.
</li>
<li>
<strong>identity</strong> Default is 'email'<br/>
Column to use for uniquely identifing user/logging in/etc.
Usual choices are 'email' OR 'username', but any unique key from your table can be used as identity.<br/>
IMPORTANT: If you are changing it from the default (email), update the UNIQUE constraint in your DB.
</li>
<li>
<strong>min_password_length</strong> Default is '8'<br/>
Minimum length of passwords.<br/>
This minimum is not enforced directly by the library.<br/>
The controller should define a validation rule to enforce it.<br/>
See the Auth controller for an example implementation.<br/><br/>
Additional note: the library will fail for empty password or password size above 4096 bytes.<br/>
This is an arbitrary (long) value to protect against DOS attack.
</li>
<li>
<strong>email_activation</strong> Default is 'false'<br/>
TRUE or FALSE. Sets whether to require email activation or not.
</li>
<li>
<strong>manual_activation</strong> Default is 'false'<br/>
TRUE or FALSE. Sets whether to require manual activation (probably by an admin user) or not.
</li>
<li>
<strong>remember_users</strong> Default is 'true'<br/>
TRUE or FALSE. Sets whether to enable 'remember me' functionality or not.
</li>
<li>
<strong>user_expire</strong> Default is '86500'<br/>
Sets how long to remember the user for in seconds. Set to zero for no expiration.
</li>
<li>
<strong>user_extend_on_login</strong> Default is 'false'<br/>
TRUE or FALSE. Extend the users session expiration on login.
</li>
<li>
<strong>track_login_attempts</strong> Default is 'false'<br/>
Track the number of failed login attempts for each user or ip (see track_login_ip_address option).
</li>
<li>
<strong>track_login_ip_address</strong> Default is 'true'<br/>
Track login attempts by IP Address, if FALSE will track based on identity.
</li>
<li>
<strong>maximum_login_attempts</strong> Default is 3<br/>
Set the maximum number of failed login attempts. This maximum is not enforced by the library, but is
used by $this->ion_auth->is_max_login_attempts_exceeded(). The controller should check this function and act appropriately.
If set to 0, there is no maximum.
</li>
<li>
<strong>forgot_password_expiration</strong> Default is 1800<br/>
Number of seconds before a forgot password request expires. If set to 0, requests will not expire.<br/>
30 minutes to 1 hour are good values (enough for a user to receive the email and reset its password).<br/>
You should not set a value too high (or 0), as it could lead to security issue!
</li>
<li>
<strong>recheck_timer</strong> Default is 0<br/>
The number of seconds after which the session is checked again against database to
see if the user still exists and is active.<br/>
Leave 0 if you don't want session recheck. if you really think you need to recheck the session
against database, we would recommend a higher value, as this would affect performance.
</li>
</ul>
<h3>Cookie options</h3>
<ul>
<li>
<strong>remember_cookie_name</strong> Default is 'remember_code'<br/>
Cookie name for the "Remember me" feature.
</li>
</ul>
<h3>Email options</h3>
<ul>
<li>
<strong>email_type</strong> Default us 'html'<br/>
Email content type.
</li>
</ul>
<h3>Templates options</h3>
<ul>
<li>
<strong>email_templates</strong> Default is 'auth/email/'<br/>
Folder where the email view templates are stored.
</li>
<li>
<strong>email_activate</strong> Default is 'activate.tpl.php'<br/>
Filname of the email activation view template.
</li>
<li>
<strong>email_forgot_password</strong> Default is 'forgot_password.tpl.php'<br/>
Filname of the forgot password email view template.
</li>
</ul>
<h3>Message Delimiters</h3>
<ul>
<li>
<strong>message_start_delimiter</strong> Default is '<p>'<br/>
Starting delimiter for messages.
</li>
<li>
<strong>message_end_delimiter</strong> Default is '</p>'<br/>
Ending delimiter for messages.
</li>
<li>
<strong>error_start_delimiter</strong> Default is '<p>'<br/>
Starting delimiter for errors.
</li>
<li>
<strong>error_end_delimiter</strong> Default is '</p>'<br/>
Ending delimiter for errors.
</li>
</ul>
<br />
<h1>Class Function Reference</h1>
<p class="important"><strong>NOTE:</strong> Methods available in the model are called through the controller using PHP5 magic. You should never use ion_auth_model->method() in your applications.</p>
<a name="login"></a>
<h2>login()</h2>
<p>Logs the user into the system.</p>
<p><strong>Parameters</strong></p>
<ol>
<li>'Identity' - string REQUIRED. Username, email or any unique value in your users table, depending on your configuration.</li>
<li>'Password' - string REQUIRED.</li>
<li>'Remember' - boolean OPTIONAL. TRUE sets the user to be remembered if enabled in the configuration.</li>
</ol>
<p><strong>Return</strong></p>
<ul>
<li>boolean. TRUE if the user was successfully logged in FALSE if the user was not logged in.</li>
</ul>
<p><strong>Usage</strong></p>
<pre>
$identity = '[email protected]';
$password = '12345678';
$remember = TRUE; // remember the user
$this->ion_auth->login($identity, $password, $remember);
</pre>
<br />
<a name="logout"></a>
<h2>logout()</h2>
<p>Logs the user out of the system.</p>
<p><strong>Usage</strong></p>
<pre>
$this->ion_auth->logout();
</pre>
<br />
<a name="register"></a>
<h2>register()</h2>
<p>Register (create) a new user.</p>
<p><strong>Parameters</strong></p>
<ol>
<li>'Identity' - string REQUIRED. This must be the value that uniquely identifies the user when he is registered. If you chose "email" as $config['identity'] in the configuration file, you must put the email of the new user.</li>
<li>'Password' - string REQUIRED.</li>
<li>'Email' - string REQUIRED.</li>
<li>'Additional Data' - multidimensional array OPTIONAL.</li>
<li>'Group' - array OPTIONAL. If not passed the default group name set in the config will be used.</li>
</ol>
<p><strong>Return</strong></p>
<ul>
<li>mixed. The ID of the user if the user was successfully created, FALSE if the user was not created.</li>
</ul>
<p><strong>Usage</strong></p>
<pre>
$username = 'benedmunds';
$password = '12345678';
$email = '[email protected]';
$additional_data = array(
'first_name' => 'Ben',
'last_name' => 'Edmunds',
);
$group = array('1'); // Sets user to admin.
$this->ion_auth->register($username, $password, $email, $additional_data, $group)
</pre>
<br />
<a name="create_user"></a>
<h2>create_user()</h2>
<p>create_user is an alternate method for <a href="#register">register()</a> method.</p>
<br />
<a name="update"></a>
<h2>update()</h2>
<p>Update a user.</p>
<p><strong>Parameters</strong></p>
<ol>
<li>'Id' - integer REQUIRED.</li>
<li>'Data' - multidimensional array REQUIRED.</li>
</ol>
<p><strong>Return</strong></p>
<ul>
<li>boolean. TRUE if the user was successfully updated FALSE if the user was not updated.</li>
</ul>
<p><strong>Usage</strong></p>
<pre>
$id = 12;
$data = array(
'first_name' => 'Ben',
'last_name' => 'Edmunds',
'password' => '123456789',
);
$this->ion_auth->update($id, $data)
</pre>
<br />
<a name="update_user"></a>
<h2>update_user()</h2>
<p>update_user() is an alternate method for <a href="#update">update()</a> method.</p>
<br />
<a name="delete_user"></a>
<h2>delete_user()</h2>
<p>Delete a user.</p>
<p><strong>Parameters</strong></p>
<ol>
<li>'Id' - integer REQUIRED.</li>
</ol>
<p><strong>Return</strong></p>
<ul>
<li>boolean. TRUE if the user was successfully deleted FALSE if the user was not deleted.</li>
</ul>
<p><strong>Usage</strong></p>
<pre>
$id = 12;
$this->ion_auth->delete_user($id)
</pre>
<br />
<a name="forgotten_password"></a>
<h2>forgotten_password()</h2>
<p>Resets a users password by emailing the user a reset code.</p>
<p><strong>Parameters</strong></p>
<ol>
<li>'Identity' - string REQUIRED. (as defined in config/ion_auth.php)</li>
</ol>
<p><strong>Return</strong></p>
<ul>
<li>boolean. TRUE if the users password was successfully reset FALSE if the users password was not reset.</li>
</ul>
<p><strong>Usage</strong></p>
<p> - this example assumes you have 'email' selected as the identity in config/ion_auth.php
<pre>
//Working code for this example is in the example Auth controller in the github repo
function forgot_password()
{
$this->form_validation->set_rules('email', 'Email Address', 'required');
if ($this->form_validation->run() == false) {
//setup the input
$this->data['email'] = array('name' => 'email',
'id' => 'email',
);
//set any errors and display the form
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
$this->load->view('auth/forgot_password', $this->data);
}
else {
//run the forgotten password method to email an activation code to the user
$forgotten = $this->ion_auth->forgotten_password($this->input->post('email'));
if ($forgotten) { //if there were no errors
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect("auth/login", 'refresh'); //we should display a confirmation page here instead of the login page
}
else {
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect("auth/forgot_password", 'refresh');
}
}
}
</pre>
<br />
<a name="forgotten_password_check"></a>
<h2>forgotten_password_check()</h2>
<p>Check to see if the forgotten password code is valid.</p>
<p><strong>Parameters</strong></p>
<ol>
<li>'Code' - string REQUIRED.</li>
</ol>
<p><strong>Return</strong></p>
<ul>
<li>object / bool. Returns the user record if valid, return FALSE if invalid.</li>
</ul>
<p><strong>Usage</strong></p>
<pre>
$user = $this->ion_auth->forgotten_password_check($code);
if ($user)
{
//display the password reset form
}
</pre>
<br />
<a name="logged_in"></a>
<h2>logged_in()</h2>
<p>Check to see if a user is logged in.</p>
<p><strong>Return</strong></p>
<ul>
<li>boolean. TRUE if the user is logged in FALSE if the user is not logged in.</li>
</ul>
<p><strong>Usage</strong></p>
<pre>
if (!$this->ion_auth->logged_in())
{
redirect('auth/login');
}
</pre>
<br />
<a name="is_admin"></a>
<h2>is_admin()</h2>
<p>Check to see if the currently logged in user is an admin.</p>
<p><strong>Parameters</strong></p>
<ol>
<li>'id' - integer OPTIONAL. If a user id is not passed the id of the currently logged in user will be used.</li>
</ol>
<p><strong>Return</strong></p>
<ul>
<li>boolean. TRUE if the user is an admin FALSE if the user is not an admin.</li>
</ul>
<p><strong>Usage</strong></p>
<pre>
if (!$this->ion_auth->is_admin())
{
$this->session->set_flashdata('message', 'You must be an admin to view this page');
redirect('welcome/index');
}
</pre>
<br />
<a name="in_group"></a>
<h2>in_group()</h2>
<p>Check to see if a user is in a group(s).</p>
<p><strong>Parameters</strong></p>
<ol>
<li>'Group ID or Name' - string REQUIRED. Integer or array of strings and integers.</li>
<li>'User ID' - integer OPTIONAL. If a user id is not passed the id of the currently logged in user will be used.</li>
<li>'Check All' - bool OPTIONAL. Whether to check if user is in all groups, or in any group.</li>
</ol>
<p><strong>Return</strong></p>
<ul>
<li>boolean. TRUE if the user is in all or any (based on passed param), FALSE otherwise.</li>
</ul>
<p><strong>Usage</strong></p>
<pre>
# single group (by name)
$group = 'gangstas';
if (!$this->ion_auth->in_group($group))
{
$this->session->set_flashdata('message', 'You must be a gangsta to view this page');
redirect('welcome/index');
}
# single group (by id)
$group = 1;
if (!$this->ion_auth->in_group($group))
{
$this->session->set_flashdata('message', 'You must be part of the group 1 to view this page');
redirect('welcome/index');
}
# multiple groups (by name)
$group = array('gangstas', 'hoodrats');
if (!$this->ion_auth->in_group($group))
$this->session->set_flashdata('message', 'You must be a gangsta OR a hoodrat to view this page');
redirect('welcome/index');
}
# multiple groups (by id)
$group = array(1, 2);
if (!$this->ion_auth->in_group($group))
$this->session->set_flashdata('message', 'You must be a part of group 1 or 2 to view this page');
redirect('welcome/index');
}
# multiple groups (by id and name)
$group = array('gangstas', 2);
if (!$this->ion_auth->in_group($group))
$this->session->set_flashdata('message', 'You must be a part of the gangstas or group 2');
redirect('welcome/index');
}
# multiple groups (by id) and check if all exist
$group = array(1, 2);
if (!$this->ion_auth->in_group($group, false, true))
$this->session->set_flashdata('message', 'You must be a part of group 1 and 2 to view this page');
redirect('welcome/index');
}
</pre>
<br />
<a name="username_check"></a>
<h2>username_check()</h2>
<p>Check to see if the username is already registered.</p>
<p><strong>Parameters</strong></p>
<ol>
<li>'Username' - string REQUIRED.</li>
</ol>
<p><strong>Return</strong></p>
<ul>
<li>boolean. TRUE if the user is registered FALSE if the user is not registered.</li>
</ul>
<p><strong>Usage</strong></p>
<pre>
//This is a lame example but it works. Usually you would use this method with form_validation.
$username = $this->input->post('username');
$password = $this->input->post('password');
$email = $this->input->post('email');
$additional_data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
);
if (!$this->ion_auth->username_check($username))
{
$group_name = 'users';
$this->ion_auth->register($username, $password, $email, $additional_data, $group_name)
}
</pre>
<br />
<a name="email_check"></a>
<h2>email_check()</h2>
<p>Check to see if the email is already registered.</p>
<p><strong>Parameters</strong></p>
<ol>
<li>'Email' - string REQUIRED.</li>
</ol>
<p><strong>Return</strong></p>
<ul>
<li>boolean. TRUE if the user is registered FALSE if the user is not registered.</li>
</ul>
<p><strong>Usage</strong></p>
<pre>
//This is a lame example but it works. Usually you would use this method with form_validation.
$username = $this->input->post('username');
$password = $this->input->post('password');
$email = $this->input->post('email');
$additional_data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
);
if (!$this->ion_auth->email_check($email))
{
$group_name = 'users';
$this->ion_auth->register($username, $password, $email, $additional_data, $group_name)
}
</pre>
<br />
<a name="identity_check"></a>
<h2>identity_check()</h2>
<p>Check to see if the identity is already registered.</p>
<p><strong>Parameters</strong></p>
<ol>
<li>'Identity' - string REQUIRED.</li>
</ol>
<p><strong>Return</strong></p>
<ul>
<li>boolean. TRUE if the user is registered FALSE if the user is not registered.</li>
</ul>
<p><strong>Usage</strong></p>
<pre>
//This is a lame example but it works.
$user = $this->ion_auth->user();
$data = array(
'identity' => $this->input->post('identity'),
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
);
if ($data['identity'] === $user->username || $data['identity'] === $user->email || $this->ion_auth->identity_check($data['identity']) === FALSE)
{
$this->ion_auth->update_user($user->id, $data)
}
</pre>
<br />
<a name="is_max_login_attempts_exceeded"></a>
<h2>is_max_login_attempts_exceeded()</h2>
<p>If login attempt tracking is enabled, checks to see if the number of failed login attempts for this identity or ip address has been exceeded.
The controller must call this method and take any necessary actions. Login attempt limits are not enforced in the library.</p>
<p><strong>Parameters</strong></p>
<ol>
<li>'Identity' - string REQUIRED.</li>
</ol>
<p><strong>Return</strong></p>
<ul>
<li>boolean. TRUE if maximum_login_attempts is exceeded FALSE if not or if login attempts not tracked.</li>
</ul>
<p><strong>Usage</strong></p>
<pre>
$identity = '[email protected]';
if ($this->ion_auth->is_max_login_attempts_exceeded($identity))
{
$this->session->set_flashdata('message', 'You have too many login attempts');
redirect('welcome/index');
}
</pre>
<br />
<a name="get_attempts_num"></a>
<h2>get_attempts_num()</h2>
<p>Returns the number of failed login attempts for this identity or ip address.</p>
<p><strong>Parameters</strong></p>
<ol>
<li>'Identity' - string REQUIRED.</li>
</ol>
<p><strong>Return</strong></p>
<ul>
<li>int. The number of failed login attempts for this identity or ip address.</li>
</ul>
<p><strong>Usage</strong></p>
<pre>
$identity = '[email protected]';
$num_attempts = $this->ion_auth->get_attempts_num($identity);
</pre>
<br />
<a name="increase_login_attempts"></a>
<h2>increase_login_attempts()</h2>
<p>If login attempt tracking is enabled, records another failed login attempt for this identity or ip address.
This method is automatically called during the login() method if the login failed.</p>
<p><strong>Parameters</strong></p>
<ol>
<li>'Identity' - string REQUIRED.</li>
</ol>
<p><strong>Usage</strong></p>
<pre>
$identity = '[email protected]';
$password = '12345678';
if ($this->ion_auth->login($identity, $password) == FALSE) {
$this->ion_auth->increase_login_attempts($identity)
}
</pre>
<br />
<a name="clear_login_attempts"></a>
<h2>clear_login_attempts()</h2>
<p>Clears all failed login attempt records for this identity or this ip address.
This method is automatically called during the login() method if the login succeded.</p>
<p><strong>Parameters</strong></p>
<ol>
<li>'Identity' - string REQUIRED.</li>
</ol>
<p><strong>Usage</strong></p>
<pre>
$identity = '[email protected]';
$password = '12345678';
if ($this->ion_auth->login($identity, $password) == TRUE) {
$this->ion_auth->clear_login_attempts($identity)
}
</pre>
<br />
<a name="user"></a>
<h2>user()</h2>
<p>Get a user.</p>
<p><strong>Parameters</strong></p>
<ol>
<li>'Id' - integer OPTIONAL. If a user id is not passed the id of the currently logged in user will be used.</li>
</ol>
<p><strong>Return</strong></p>
<ul>
<li>
<pre>
stdClass Object (
[id] => 1
[ip_address] => 127.0.0.1
[username] => administrator
[password] => 59beecdf7fc966e2f17fd8f65a4a9aeb09d4a3d4
[email] => [email protected]
[activation_code] => 19e181f2ccc2a7ea58a2c0aa2b69f4355e636ef4
[forgotten_password_code] => 81dce1d0bc2c10fbdec7a87f1ff299ed7e4c9e4a
[remember_code] => 9d029802e28cd9c768e8e62277c0df49ec65c48c
[created_on] => 1268889823
[last_login] => 1279464628
[active] => 0
[first_name] => Admin
[last_name] => Account
[company] => Some Corporation
[phone] => (123)456-7890
)
</pre>
</li>
</ul>
<p><strong>Usage</strong></p>
<pre>
$user = $this->ion_auth->user()->row();
echo $user->email;
</pre>
<br />
<a name="users"></a>
<h2>users()</h2>
<p>Get the users.</p>
<p><strong>Parameters</strong></p>
<ol>
<li>'Group IDs, group names, or group IDs and names' - array OPTIONAL. If an array of group ids, of group names, or of group ids and names are passed (or a single group id or name) this will return the users in those groups.</li>
</ol>
<p><strong>Return</strong></p>
<ul>
<li>model object</li>
</ul>
<p><strong>Usage</strong></p>
<pre>
$users = $this->ion_auth->users()->result(); // get all users
</pre>
<br />
<pre>
$users = $this->ion_auth->users(1)->result(); // get users from group with id of '1'
</pre>
<br />
<pre>
$users = $this->ion_auth->users('members')->result(); // get users from 'members' group
</pre>
<br />
<pre>
$users = $this->ion_auth->users(array('admin','members'))->result(); // get users from 'admin' and 'members' group
</pre>
<br />
<pre>
$users = $this->ion_auth->users(array('admin',4,'members'))->result(); // get users from 'admin' group, 'members' group and group with id '4'
</pre>
<br />
<pre>
$users = $this->ion_auth->users(1)->result(); // get users from group with id of '1'
</pre>
<br />
<pre>
$users = $this->ion_auth->users('members')->result(); // get users from 'members' group
</pre>