From f3f0262c480d7e509b008d37c90aed884532bba8 Mon Sep 17 00:00:00 2001 From: andi Date: Wed, 12 Jan 2005 21:24:54 +0100 Subject: Initial revision. darcs-hash:20050112202454-9977f-60936f24fe2092a30223627e0683de2df61d0c4a.gz --- inc/auth.php | 290 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 290 insertions(+) create mode 100644 inc/auth.php (limited to 'inc/auth.php') diff --git a/inc/auth.php b/inc/auth.php new file mode 100644 index 000000000..825ecb9d2 --- /dev/null +++ b/inc/auth.php @@ -0,0 +1,290 @@ + $perm){ + $perm = $acl[2]; + } + } + if($perm > -1){ + //we had a match - return it + return $perm; + } + } + + //still here? do the namespace checks + if($ns){ + $path = $ns.':\*'; + }else{ + $path = '\*'; //root document + } + + do{ + $matches = preg_grep('/^'.$path.'\s+('.$regexp.')\s+/',$AUTH_ACL); + if(count($matches)){ + foreach($matches as $match){ + $match = preg_replace('/#.*$/','',$match); //ignore comments + $acl = preg_split('/\s+/',$match); + if($acl[2] > $perm){ + $perm = $acl[2]; + } + } + //we had a match - return it + return $perm; + } + + //get next higher namespace + $ns = getNS($ns); + + if($path != '\*'){ + $path = $ns.':\*'; + if($path == ':\*') $path = '\*'; + }else{ + //we did this already + //looks like there is something wrong with the ACL + //break here + return $perm; + } + }while(1); //this should never loop endless +} + +/** + * Create a pronouncable password + * + * @see: http://www.phpbuilder.com/annotate/message.php3?id=1014451 + */ +function auth_pwgen(){ + $pw = ''; + $c = 'bcdfghjklmnprstvwz'; //consonants except hard to speak ones + $v = 'aeiou'; //vowels + $a = $c.$v; //both + + //use two syllables... + for($i=0;$i < 2; $i++){ + $pw .= $c[rand(0, strlen($c)-1)]; + $pw .= $v[rand(0, strlen($v)-1)]; + $pw .= $a[rand(0, strlen($a)-1)]; + } + //... and add a nice number + $pw .= rand(10,99); + + return $pw; +} + +/** + * Sends a password to the given user + * + * returns true on success + */ +function auth_sendPassword($user,$password){ + global $conf; + global $lang; + $users = auth_loadUserData(); + $hdrs = ''; + + if(!$users[$user]['mail']) return false; + + $text = rawLocale('password'); + $text = str_replace('@DOKUWIKIURL@',getBaseURL(true),$text); + $text = str_replace('@FULLNAME@',$users[$user]['name'],$text); + $text = str_replace('@LOGIN@',$user,$text); + $text = str_replace('@PASSWORD@',$password,$text); + $text = str_replace('@TITLE@',$conf['title'],$text); + + if (!empty($conf['mailfrom'])) { + $hdrs = 'From: '.$conf['mailfrom']."\n"; + } + return @mail($users[$user]['mail'],$lang['regpwmail'],$text,$hdrs); +} + +/** + * The new user registration - we get our info directly from + * $_POST + * + * It returns true on success and false on any error + */ +function register(){ + global $lang; + global $conf; + + if(!$_POST['save']) return false; + if(!$conf['openregister']) return false; + + //clean username + $_POST['login'] = preg_replace('/.*:/','',$_POST['login']); + $_POST['login'] = cleanID($_POST['login']); + //clean fullname and email + $_POST['fullname'] = trim(str_replace(':','',$_POST['fullname'])); + $_POST['email'] = trim(str_replace(':','',$_POST['email'])); + + if( empty($_POST['login']) || + empty($_POST['fullname']) || + empty($_POST['email']) ){ + msg($lang['regmissing'],-1); + return false; + } + + //check mail + if(!isvalidemail($_POST['email'])){ + msg($lang['regbadmail'],-1); + return false; + } + + //okay try to create the user + $pass = auth_createUser($_POST['login'],$_POST['fullname'],$_POST['email']); + if(empty($pass)){ + msg($lang['reguexists'],-1); + return false; + } + + //send him the password + if (auth_sendPassword($_POST['login'],$pass)){ + msg($lang['regsuccess'],1); + return true; + }else{ + msg($lang['regmailfail'],-1); + return false; + } +} + +/** + * Uses a regular expresion to check if a given mail address is valid + * + * @see http://www.webmasterworld.com/forum88/135.htm + * + * May not be completly RFC conform! + */ +function isvalidemail($email){ + return eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$", $email); +} + +?> -- cgit v1.2.3