]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - doc/README.phpwiki-auth
various
[SourceForge/phpwiki.git] / doc / README.phpwiki-auth
1 UserAuthentification
2
3 !!! The new phpwiki user authentification and preferences settings
4
5 A typical wiki needs no authentification, some wiki's support a so called 
6 "Bogo" login, where the username is a wikiword and therefore any note on any page
7 (typically ended with "--UserName") is automatically linked to the users homepage 
8 on this wiki.
9 PhpWiki supported anonymous edits from the beginning, 
10 non-anonymous edits, with required BogoLogin since version ???
11 and true user identification with required username and passwords since 1.3.4, 
12 where the optional password was stored in the users HomePage metadata.
13 Seperately PhpWiki could be hacked to be protected by HTTP Auth 
14 (e.g. Apache's .htaccess <require>), the username would then be 
15 $PHP_AUTH_USER and the password not needed.
16
17 Since version 1.3.4 ReiniUrban was working on UserAuthentificationNew
18 to support authentification against external sources also, such as a 
19 mysql database, LDAP or IMAP or .htaccess like files.
20 From version 1.3.4 to 1.3.7 only HTTP Auth, LDAP, and IMAP was supported,
21 the configuration settings for the planned (and already written) DbAuth code 
22 was in index.php, but it was never enabled (which probably lead to some confusion).
23 Since version 1.3.8 UserAuthentificationNew is enabled.
24
25 We have to seperate various storage methods for UserPreferences
26 (cookie, PersonalPage and database), various retrieval methods for 
27 username-password pairs (AuthMethods) and various AuthPolicies.
28
29 !! New constants and variables:
30 * ALLOW_ANON_USER         default: true
31 * ALLOW_ANON_EDIT         default: true
32 * ALLOW_BOGO_LOGIN        default: true
33 * ALLOW_USER_PASSWORDS    default: true
34 * PASSWORD_LENGTH_MINIMUM default: 6
35 * $USER_AUTH_ORDER~[~]      default: ("PersonalPage","Db")
36 * USER_AUTH_POLICY        default: "old"
37 * $DBAuthParams~[~]         see below
38
39 Temporarily:
40 ; ENABLE_USER_NEW : This will be removed with the 1.3.8 release. It's just to decide if ~WikiUserNew.php should be loaded instead of the old ~WikiUser.php
41
42 ! ALLOW_ANON_USER
43 To establish a COMPLETELY private wiki, such as an internal corporate one
44 set ALLOW_ANON_USER = false, and probably require user passwords as described below. 
45 In this case the user will be prompted to login immediately upon accessing
46 any page. This is similar to HttpAuth.
47
48 ! ALLOW_ANON_EDIT
49 This feature was called REQUIRE_SIGNIN_BEFORE_EDIT before. To enable ALLOW_BOGO_LOGIN and/or ALLOW_USER_PASSWORDS, ALLOW_ANON_EDIT must be false, otherwise it will override ALLOW_BOGO_LOGIN and ALLOW_USER_PASSWORDS. This will go away, with true page permissions. 
50
51 ! ALLOW_BOGO_LOGIN
52 If ALLOW_BOGO_LOGIN is true, users are allowed to login (with any/no password) using any userid which: 
53   1) is not the ADMIN_USER, and
54   2) is a valid WikiWord (matches $WikiNameRegexp.)
55 If true, users may be created by themselves. Otherwise we need seperate ALLOW_USER_PASSWORDS auth. 
56 If such a user will create a so called HomePage named after his WikiWord userid, he will be able to store his preferences and password there.
57 If ALLOW_ANON_EDIT = true, one may still sign in to be able to store UserPreferences and named RecentChanges entries.
58 PASSWORD_LENGTH_MINIMUM is ignored by bogo login attempts.
59 If an empty password is used, any user can sign in with this userid.
60
61 ! REQUIRE_SIGNIN_BEFORE_EDIT (Legacy)
62 If set, then if an anonymous user attempts to edit a page he will
63 be required to sign in. This constant was replaced by ALLOW_ANON_EDIT in v1.3.8.
64 If ALLOW_BOGO_LOGIN is true, of course, no password is required, but the user must still sign in under some sort of WikiWord name. This will go away, with true page permissions.
65
66 ! ALLOW_USER_PASSWORDS
67 True User Authentification is used with Bogo Login and not-empty passwords or ALLOW_USER_PASSWORDS = true.
68 To require user passwords set
69 <verbatim>
70    ALLOW_ANON_EDIT  = false
71    ALLOW_BOGO_LOGIN = false
72    ALLOW_USER_PASSWORDS = true
73 </verbatim>
74 Otherwise any anon or bogo user might login without any or a wrong password. A login attempt with ALLOW_USER_PASSWORDS = true depends on the defined USER_AUTH_ORDER auth methods, the USER_AUTH_POLICY and PASSWORD_LENGTH_MINIMUM.
75
76 !! FAQ - UPGRADE PROBLEMS:
77
78 * ''Fatal error: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition wikiuser of the object you are trying to operate on was loaded _before_ the session was started in...''
79
80 This error will appear you switch from old (or from new to old) in the same browser session. You have an old (or new) WikiUser object in your current session, which is incompatible with the new (or old) WikiUser object on session restauration. 
81 Workaround: Close and open your browser again. The session cookie should be destroyed, and you will get a fresh new WikiUser object. Your default WIKI_ID (your username) will not be lost.
82
83 * ''lib\Template.php:22: Warning[2]: fopen("", "rb") - No such file or directory''
84
85 PHPWIKI_DIR could not be determined automatically. You probably started from a different diretory.
86 Workaround: Set PHPWIKI_DIR in index.php or in your start script. You most likely have to set DATA_PATH also, when your pages look like the ancient-style Wiki (Times-Roman, black-white), i.e. no CSS is loaded.
87
88
89 Below we define which methods exists and in which order theys are used:
90
91 !! USER_AUTH_ORDER auth methods
92
93 $USER_AUTH_ORDER is an array of the following strings. You can en-/disable any and change the order.
94
95 * __~BogoLogin__:  This will eventually replace the old ALLOW_BOGO_LOGIN constant, but it will require PASSWORD_LENGTH_MINIMUM. So non-empty passwords can be disabled.
96 * __~PersonalPage__:  Store passwords in the users homepage metadata (simple)
97 * __~HttpAuth__:  Use the protection by the webserver, either .htaccess or httpd.conf
98 * __Db__:        Use $DBAuthParams~[~] (see below) with PearDB or ADODB only. If 'auth_dsn' is undefined, and wiki pages are stored via SQL or ADODB, it uses the same database. (fastest)
99 * __LDAP__:      Authenticate against LDAP_AUTH_HOST with the LDAP_AUTH_SEARCH settings
100 * __IMAP__:      Authenticate against IMAP_AUTH_HOST (e.g. an existing email account)
101 * __File__:      Check username:crypted-passwords in .htaccess like files. Use Apache's htpasswd program to manage this file.
102
103 Each method is a WikiUser (in fact a ~_PassUser) class, which defines the checkPass() and userExists() methods and optionally mayChangePass() and storePass().
104
105 !! USER_AUTH_POLICY
106
107 The available policies defines how and when each auth method from USER_AUTH_ORDER is tried, and what to do on failure. Some policies require to know it at advance at initialization time, some have to check if a valid user exists and some simply check valid username - password pairs.
108
109 ;__old__:   This policy checks all default USER_AUTH_ORDER methods, disables all not defined services (ldap, imap) and tries to use all available methods as in the previous PhpWiki releases with the stacked policy (slow).
110 ;__first-only__: use only the first method in USER_AUTH_ORDER
111 ;__strict__:    check if the user exists for all methods: on the first existing user, try the password. dont try the other methods on failure then
112 ;__stacked__:    check the given user - password combination for all methods and return true on the first success.
113
114 ! AUTH_FILE_* constants
115
116   ''ToDo''
117
118 ! $DBAuthParams~[~]
119 Statements for seperate DB User Authentication.
120
121 This array defines the database prepare statements to select and update the password and preferences.
122 This is typically used to interface with other applications or user databases in quasi secure wiki's. 
123 (often so called "Content Management Systems").
124 The database can be external like radius, phpnuke, courier authmysql, apache auth_mysql or just a simple 
125 user table within phpwiki.
126 The most likely auth_dsn option is the same dsn as the wikipages, in fact if it's empty $DBParams~['dsn'~] is used.
127 If $DBParams~['db_type'~] is not ADODB, the Pear DB library is used (db_type = SQL).
128
129 This is the list of the available options and some examples. For the statements we use the following symbolic variables:
130    $user_id   : loginname
131    $password  : plain or encrypted password
132    $pref_blob : serialized string of the PHP preferences array (may get large, but not too large. 128 - 1024. mysql TEXT is enough)
133    $groupname     : groupname
134 Note: The symbolic variables (like "$password", ...) must be enclosed in double quotes!
135 ADODB Note: With ADODB we must define the correct alias names: SELECT db_column as name
136
137 ;auth_dsn:     'mysql://user@password:localhost/phpwiki'
138
139 USER => PASSWORD
140
141 ;auth_crypt_method: 'crypt' (simple unix crypt, not md5 crypt, sha1 or else) or 'plain' (also for mysql md5)
142
143 ;auth_check:     needs "$password" and "$userid", returns ok with plain or the password with crypt
144
145 'auth_crypt_method' = 'plain':
146   'SELECT IF(passwd="$password",1,0) as ok FROM user WHERE username="$userid"' or 
147   'SELECT IF(passwd=PASSWORD("$password"),1,0) as ok FROM user WHERE username="$userid"',
148
149 'auth_crypt_method' = 'crypt':
150   'SELECT password as password FROM user WHERE username="$userid"',
151
152 auth_user_exists is only needed with auth_crypt_method = plain and USER_AUTH_POLICY = stacked or old:
153 ;auth_user_exists:  'SELECT username as userid FROM user WHERE username="$userid"'
154
155 ;auth_update:  'UPDATE user SET password="$password" WHERE username="$userid"' or 
156   'UPDATE user SET password=PASSWORD("$password") WHERE username="$userid"'
157 ;user_create:  'INSERT INTO user SET username="$userid", password="$password", pref="$pref_blob"'
158
159 If auth_update is not defined but auth_check is defined, the user cannot change his password. But then better crypt methods may be used also. $password is processed by the auth_crypt_method.
160 For mysql md5-crypt use auth_crypt_method = plain and 'UPDATE user SET password=PASSWORD("$password") WHERE username="$userid"'
161
162 user_create is typically undefined, but may be defined to get rid of PersonalPage users completely.
163
164 auth_user_exists is only needed with auth_crypt_method = plain and USER_AUTH_POLICY = stacked or old or for certain plugins which want to list all users. With auth_crypt_method = crypt the auth_check statement is used for the userExists() check.
165
166 USER => PREFERENCES
167
168 This can be optionally defined in an external DB. The default is the users homepage.
169
170 ;pref_select: 'SELECT pref as pref FROM user WHERE username="$userid"',
171 ;pref_update: 'UPDATE user SET pref="$pref_blob" WHERE username="$userid"',
172
173 USERS <=> GROUPS
174
175 DB methods for lib/WikiGroup.php. This can be optionally defined in a file (see AUTH_GROUP_FILE) or an external DB. The default storage location is a special locked wikipage named after the group and as content a list of all groupmembers.
176
177 ;is_member:     'SELECT 1 FROM groups WHERE user=$userid"" AND group="$groupname"',
178 ;group_members: ''All members of the group.'' 'SELECT username FROM grouptable WHERE groupname="$groupname"'
179 ;user_groups:   ''All groups this user belongs to.'' 'SELECT groupname FROM grouptable WHERE username="$userid"'
180
181 ----
182
183 !! UserPreferences
184
185 The preferences are stored as serialized hash of non-default values, at the following locations:
186
187 # Cookie
188 # PersonalPage 
189 # Database
190
191 ~AnonUser uses Cookie alone. For signed in users (~BogoUser and higher) the PersonalPage and/or Database methods 
192 are tried. If these methods fail (no such page or user exists) the Cookie method will be used.
193 For some short time a serialized array of _UserPreference objects was stored which was "not a good thing".
194 There is code to detect these objects and convert them automatically.
195
196 To use the "PersonalPage" location a page with the same name as the userid must exist, the so called "HomePage". This does not need be a WikiWord pagename but it sure helps.
197
198 If $DBAuthParams~['pref_select'~] is defined, PersonalPage preferences are ignored and the preferences are read from the database. If $DBAuthParams~['pref_update'~] is defined, the preferences are stored back into the database.
199
200 !! Groups
201
202 Group membership information can be stored in 
203 # group wikipage
204 # database
205 # file
206
207 For the group wikipage you have to create for every group a page with a list of users and the 
208 master group page called "CategoryGroup".
209
210 For the database setup you can define the following $DBAuthParams[] statements. 
211 You can define 1:n or n:m user<=>group relations, as you wish.
212 Note: Only the PearDB library may be used so far.
213
214 Sample configurations
215
216 <verbatim>
217 only one group per user:
218   'is_member'     'SELECT 1 FROM user WHERE user=$userid"" AND group="$groupname"',
219   'group_members' 'SELECT user FROM user WHERE group="$groupname"'
220   'user_groups'   'SELECT group FROM user WHERE user="$userid"'
221
222 or multiple groups per user (n:m):
223
224   'is_member'  'SELECT 1 FROM groups WHERE user=$userid"" AND group="$groupname"'
225   'group_members'  'SELECT DISTINCT user FROM groups WHERE group="$groupname"'
226   'user_groups'  'SELECT group FROM groups WHERE user="$userid"'
227 </verbatim>
228
229 Files are defined similar to unix /etc/groups, exactly like apache htgroup files:
230
231 AUTH_GROUP_FILE = '<filename>'
232 <verbatim>
233   group1: user1 user2 user3 ...
234   group2: ...
235 </verbatim>
236
237 --ReiniUrban