]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - doc/README.phpwiki-auth
the auth README
[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 Below we define which methods exists and in which order theys are used:
77
78 !! USER_AUTH_ORDER auth methods
79
80 $USER_AUTH_ORDER is an array of the following strings. You can en-/disable any and change the order.
81
82 * __~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.
83 * __~PersonalPage__:  Store passwords in the users homepage metadata (simple)
84 * __~HttpAuth__:  Use the protection by the webserver, either .htaccess or httpd.conf
85 * __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)
86 * __LDAP__:      Authenticate against LDAP_AUTH_HOST with the LDAP_AUTH_SEARCH settings
87 * __IMAP__:      Authenticate against IMAP_AUTH_HOST (e.g. an existing email account)
88 * __File__:      Check username:crypted-passwords in .htaccess like files. Use Apache's htpasswd program to manage this file.
89
90 Each method is a WikiUser (in fact a ~_PassUser) class, which defines the checkPass() and userExists() methods and optionally mayChangePassword() and storePass().
91
92 !! USER_AUTH_POLICY
93
94 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 ad advance at initialization time, some have to check if a valid user exists and some simply check valid username - password pairs.
95
96 ;__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).
97 ;__first-only__: use only the first method in USER_AUTH_ORDER
98 ;__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
99 __stacked__:    check the given user - password combination for all methods and return true on the first success.
100
101 ! AUTH_FILE_* constants
102
103   ''ToDo''
104
105 ! $DBAuthParams~[~]
106 Statements for seperate DB User Authentication.
107
108 This array defines the database prepare statements to select and update the password and preferences.
109 This is typically used to interface with other applications or user databases in quasi secure wiki's. 
110 (often so called "Content Management Systems").
111 The database can be external like radius, phpnuke, courier authmysql, apache auth_mysql or just a simple 
112 user table within phpwiki.
113 The most likely auth_dsn option is the same dsn as the wikipages, in fact if it's empty $DBParams~['dsn'~] is used.
114 If $DBParams~['db_type'~] is not ADODB, the Pear DB library is used (db_type = SQL).
115
116 This is the list of the available options and some examples. For the statements we use the following symbolic variables:
117    $user_id   : loginname
118    $password  : plain or encrypted password
119    $pref_blob : serialized string of the PHP preferences array (may get large, but not too large. 128 - 1024. mysql TEXT is enough)
120    $groupname     : groupname
121 Note: The symbolic variables (like "$password", ...) must be enclosed in double quotes!
122 ADODB Note: With ADODB we must define the correct alias names: SELECT db_column as name
123
124 ;auth_dsn:     'mysql://user@password:localhost/phpwiki'
125
126 USER => PASSWORD
127
128 ;auth_crypt_method: 'crypt' (simple unix crypt, not md5 crypt, sha1 or else) or 'plain' (also for mysql md5)
129
130 ;auth_check:     needs "$password" and "$userid", returns ok with plain or the password with crypt
131
132 'auth_crypt_method' = 'plain':
133   'SELECT IF(passwd="$password",1,0) as ok FROM user WHERE username="$userid"' or 
134   'SELECT IF(passwd=PASSWORD("$password"),1,0) as ok FROM user WHERE username="$userid"',
135
136 'auth_crypt_method' = 'crypt':
137   'SELECT password as password FROM user WHERE username="$userid"',
138
139 auth_user_exists is only needed with auth_crypt_method = plain and USER_AUTH_POLICY = stacked or old:
140 ;auth_user_exists:  'SELECT username as userid FROM user WHERE username="$userid"'
141
142 ;auth_update:  'UPDATE user SET password="$password" WHERE username="$userid"' or 
143   'UPDATE user SET password=PASSWORD("$password") WHERE username="$userid"'
144 ;user_create:  'INSERT INTO user SET username="$userid", password="$password", pref="$pref_blob"'
145
146 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.
147 For mysql md5-crypt use auth_crypt_method = plain and 'UPDATE user SET password=PASSWORD("$password") WHERE username="$userid"'
148
149 user_create is typically undefined, but may be defined to get rid of PersonalPage users completely.
150
151 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.
152
153 USER => PREFERENCES
154
155 This can be optionally defined in an external DB. The default is the users homepage.
156
157 ;pref_select: 'SELECT pref as pref FROM user WHERE username="$userid"',
158 ;pref_update: 'UPDATE user SET pref="$pref_blob" WHERE username="$userid"',
159
160 USERS <=> GROUPS
161
162 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.
163
164 ;is_member:     'SELECT 1 FROM groups WHERE user=$userid"" AND group="$groupname"',
165 ;group_members: ''All members of the group.'' 'SELECT username FROM grouptable WHERE groupname="$groupname"'
166 ;user_groups:   ''All groups this user belongs to.'' 'SELECT groupname FROM grouptable WHERE username="$userid"'
167
168 ----
169
170 !! UserPreferences
171
172 The preferences are stored as serialized hash of non-default values, at the following locations:
173
174 # Cookie
175 # PersonalPage 
176 # Database
177
178 ~AnonUser uses Cookie alone. For signed in users (~BogoUser and higher) the PersonalPage and/or Database methods 
179 are tried. If these methods fail (no such page or user exists) the Cookie method will be used.
180 For some short time a serialized array of _UserPreference objects was stored which was "not a good thing".
181 There is code to detect these objects and convert them automatically.
182
183 To use the "PersonalPage" location a page with the same name as the userid must exist, the so called "HomePage". This does need be a WikiWord pagename but it sure helps.
184
185 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.
186
187 !! Groups
188
189 Group membership information can be stored in 
190 # group wikipage
191 # database
192 # file
193
194 For the group wikipage you have to create for every group a page with a list of users and the 
195 master group page called "CategoryGroup".
196
197 For the database setup you can define the following $DBAuthParams[] statements. 
198 You can define 1:n or n:m user<=>group relations, as you wish.
199 Note: Only the PearDB library may be used so far.
200
201 Sample configurations
202
203 <verbatim>
204 only one group per user:
205   'is_member'     'SELECT 1 FROM user WHERE user=$userid"" AND group="$groupname"',
206   'group_members' 'SELECT user FROM user WHERE group="$groupname"'
207   'user_groups'   'SELECT group FROM user WHERE user="$userid"'
208
209 or multiple groups per user (n:m):
210
211   'is_member'  'SELECT 1 FROM groups WHERE user=$userid"" AND group="$groupname"'
212   'group_members'  'SELECT DISTINCT user FROM groups WHERE group="$groupname"'
213   'user_groups'  'SELECT group FROM groups WHERE user="$userid"'
214 </verbatim>
215
216 Files are defined similar to unix /etc/groups, exactly like apache htgroup files:
217
218 AUTH_GROUP_FILE = '<filename>'
219 <verbatim>
220   group1: user1 user2 user3 ...
221   group2: ...
222 </verbatim>
223
224 --ReiniUrban