3 This plugin allows to use an existing SQL database table with usernames
4 and passwords for authentication purposes. Works with MySQL or the
7 Prior usage you must configure, which database table and field names
8 to retrieve the user information from. Additionally it is possible to
9 substitute the "$ewiki_ring" level (= admin or moderator privileges)
10 from there, if a column exists with that purpose.
13 + EWIKI_PROTECTED_MODE=1
14 + one auth_perm_* plugin
15 + one auth_method_* plugin
20 $ewiki_plugins["auth_userdb"] = "ewiki_auth_userdb_sql";
23 function ewiki_auth_userdb_sql($username) {
25 #-- function names (don't change)
26 $sql_query = "mysql_query";
27 $sql_fetch = "mysql_fetch_array";
28 # $sql_query = "anydb_query";
29 # $sql_fetch = "anydb_fetch_array";
31 #-- set your CMS' user table and column names here
35 #-- you can OPTIONALLY map privilege level strings to ewiki ring level ints:
36 $COL_PRIV = "privilege";
37 $MAP_PRIV = array("guest"=>3, "user"=>2, "moderator"=>1, "admin"=>0);
39 #-- examples for some common CMS and dynamic web site systems
41 //$TABLE="nuke_users"; $COL_USER="pn_name"; $COL_PW="pn_pass";
44 //$TABLE="ps_users"; $COL_USER="uname"; $COL_PW="pass";
45 //$COL_PRIV="status"; $MAP_PRIV("member"=>2, "Admin"=>0);
47 //$TABLE="cowiki_user"; $COL_USER="name"; $COL_PW="passwd";
50 //$TABLE="user"; $COL_USER="user_name"; $COL_PW="user_password";
51 //$COL_PRIV="user_admin"; $MAP_PRIV(0=>2, 1=>0);
53 //$TABLE="gl_user"; $COL_USER="username"; $COL_PW="passwd";
59 $username = addslashes($username); # (not really necessary here anymore)
61 #-- search username and password
62 if (($result = $sql_query("select $COL_PW from $TABLE where $COL_USER='$username'")) && ($row = $sql_fetch($result))) {
65 $ret[0] = $row[$COL_PW];
66 $ret[1] = 2; // default ring level
68 #-- fetch privilege level, if there is a table row for it
69 if ($COL_PRIV && ($result = $sql_query("select $COL_PRIV from $TABLE where $COL_USER='$username'")) && ($row = $sql_fetch($result))) {
71 #-- map priviliege names/values to ewikis' ring level integers
72 if (isset($i) && isset($MAP_PRIV[$i])) {
73 $ret[1] = $MAP_PRIV[$i];