diff options
author | andi <andi@splitbrain.org> | 2005-06-05 12:38:42 +0200 |
---|---|---|
committer | andi <andi@splitbrain.org> | 2005-06-05 12:38:42 +0200 |
commit | f62ea8a1d1cf10eddeae777b11420624e111b7ea (patch) | |
tree | 87a15e898308a5de1ef37874645a4cdcb83c707b /inc/auth/plain.php | |
parent | 248a73214063d2fe47787c8c4aa292777cddb12b (diff) | |
download | rpg-f62ea8a1d1cf10eddeae777b11420624e111b7ea.tar.gz rpg-f62ea8a1d1cf10eddeae777b11420624e111b7ea.tar.bz2 |
directory layout cleanup !IMPORTANT
This patch changes the directory structure of dokuwiki as suggested
in http://www.freelists.org/archives/dokuwiki/06-2005/msg00045.html
As the changes.log is not managed through darcs you need to move it your
self to the new location in data/changes.log
I think I modified the code at all nessessary places, but I may have
forgotten a few things.
darcs-hash:20050605103842-9977f-af20f63c1d604888375d175d89ac6bd71566d47d.gz
Diffstat (limited to 'inc/auth/plain.php')
-rw-r--r-- | inc/auth/plain.php | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/inc/auth/plain.php b/inc/auth/plain.php new file mode 100644 index 000000000..eaa01b79d --- /dev/null +++ b/inc/auth/plain.php @@ -0,0 +1,113 @@ +<?php +/** + * Plaintext authentication backend + * + * If you want to authenticate against something + * else then the builtin flatfile auth system + * you have to reimplement the "required auth + * functions" + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Andreas Gohr <andi@splitbrain.org> + */ + +// we only accept page ids for auth_plain +if(isset($_REQUEST['u'])) + $_REQUEST['u'] = cleanID($_REQUEST['u']); + +/** + * Check user+password [required auth function] + * + * Checks if the given user exists and the given + * plaintext password is correct + * + * @author Andreas Gohr <andi@splitbrain.org> + * @return bool + */ +function auth_checkPass($user,$pass){ + $users = auth_plain_loadUserData(); + + if(!isset($users[$user])) return false; + + return auth_verifyPassword($pass,$users[$user]['pass']); +} + +/** + * Return user info [required auth function] + * + * Returns info about the given user needs to contain + * at least these fields: + * + * name string full name of the user + * mail string email addres of the user + * grps array list of groups the user is in + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function auth_getUserData($user){ + $users = auth_plain_loadUserData(); + return $users[$user]; +} + +/** + * Create a new User [required auth function] + * + * Returns false if the user already exists, null when an error + * occured and the cleartext password of the new user if + * everything went well. + * + * The new user HAS TO be added to the default group by this + * function! + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function auth_createUser($user,$pass,$name,$mail){ + global $conf; + + $users = auth_plain_loadUserData(); + if(isset($users[$user])) return false; + + $userline = join(':',array($user, + auth_cryptPassword($pass), + $name, + $mail, + $conf['defaultgroup'])); + $userline .= "\n"; + $fh = fopen(DOKU_INC.'conf/users.auth.php','a'); + if($fh){ + fwrite($fh,$userline); + fclose($fh); + return $pass; + } + msg('The users.auth.php file is not writable. Please inform the Wiki-Admin',-1); + return null; +} + +/** + * Load all user data + * + * Used by the plaintext auth functions + * loads the user file into a datastructure + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function auth_plain_loadUserData(){ + $data = array(); + $lines = file(DOKU_INC.'conf/users.auth.php'); + foreach($lines as $line){ + $line = preg_replace('/#.*$/','',$line); //ignore comments + $line = trim($line); + if(empty($line)) continue; + + $row = split(":",$line,5); + $groups = split(",",$row[4]); + $data[$row[0]]['pass'] = $row[1]; + $data[$row[0]]['name'] = urldecode($row[2]); + $data[$row[0]]['mail'] = $row[3]; + $data[$row[0]]['grps'] = $groups; + } + return $data; +} + + +//Setup VIM: ex: et ts=2 enc=utf-8 : |