1<?php 2/** 3 * Authentication library 4 * 5 * Including this file will automatically try to login 6 * a user by calling auth_login() 7 * 8 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 9 * @author Andreas Gohr <andi@splitbrain.org> 10 */ 11 12 if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); 13 require_once(DOKU_INC.'inc/common.php'); 14 require_once(DOKU_INC.'inc/io.php'); 15 16 if($conf['useacl']){ 17 require_once(DOKU_INC.'inc/blowfish.php'); 18 require_once(DOKU_INC.'inc/mail.php'); 19 20 // load the the backend auth functions and instantiate the auth object 21 if (@file_exists(DOKU_INC.'inc/auth/'.$conf['authtype'].'.class.php')) { 22 require_once(DOKU_INC.'inc/auth/basic.class.php'); 23 require_once(DOKU_INC.'inc/auth/'.$conf['authtype'].'.class.php'); 24 25 $auth_class = "auth_".$conf['authtype']; 26 if (class_exists($auth_class)) { 27 $auth = new $auth_class(); 28 if ($auth->success == false) { 29 unset($auth); 30 msg($lang['authtempfail'], -1); 31 32 // turn acl config setting off for the rest of this page 33 $conf['useacl'] = 0; 34 } 35 } else { 36 nice_die($lang['authmodfailed']); 37 } 38 } else { 39 nice_die($lang['authmodfailed']); 40 } 41 } 42 43 if (!defined('DOKU_COOKIE')) define('DOKU_COOKIE', 'DW'.md5($conf['title'])); 44 45 // some ACL level defines 46 define('AUTH_NONE',0); 47 define('AUTH_READ',1); 48 define('AUTH_EDIT',2); 49 define('AUTH_CREATE',4); 50 define('AUTH_UPLOAD',8); 51 define('AUTH_DELETE',16); 52 define('AUTH_ADMIN',255); 53 54 // do the login either by cookie or provided credentials 55 if($conf['useacl']){ 56 // if no credentials were given try to use HTTP auth (for SSO) 57 if(!$_REQUEST['u'] && !$_COOKIE[DOKU_COOKIE] && $_SERVER['PHP_AUTH_USER']){ 58 $_REQUEST['u'] = $_SERVER['PHP_AUTH_USER']; 59 $_REQUEST['p'] = $_SERVER['PHP_AUTH_PW']; 60 } 61 62 // external trust mechanism in place? 63 if(!is_null($auth) && $auth->canDo('external')){ 64 $auth->trustExternal($_REQUEST['u'],$_REQUEST['p'],$_REQUEST['r']); 65 }else{ 66 auth_login($_REQUEST['u'],$_REQUEST['p'],$_REQUEST['r']); 67 } 68 69 //load ACL into a global array 70 if(is_readable(DOKU_CONF.'acl.auth.php')){ 71 $AUTH_ACL = file(DOKU_CONF.'acl.auth.php'); 72 }else{ 73 $AUTH_ACL = array(); 74 } 75 } 76 77/** 78 * This tries to login the user based on the sent auth credentials 79 * 80 * The authentication works like this: if a username was given 81 * a new login is assumed and user/password are checked. If they 82 * are correct the password is encrypted with blowfish and stored 83 * together with the username in a cookie - the same info is stored 84 * in the session, too. Additonally a browserID is stored in the 85 * session. 86 * 87 * If no username was given the cookie is checked: if the username, 88 * crypted password and browserID match between session and cookie 89 * no further testing is done and the user is accepted 90 * 91 * If a cookie was found but no session info was availabe the 92 * blowfish encrypted password from the cookie is decrypted and 93 * together with username rechecked by calling this function again. 94 * 95 * On a successful login $_SERVER[REMOTE_USER] and $USERINFO 96 * are set. 97 * 98 * @author Andreas Gohr <andi@splitbrain.org> 99 * 100 * @param string $user Username 101 * @param string $pass Cleartext Password 102 * @param bool $sticky Cookie should not expire 103 * @return bool true on successful auth 104*/ 105function auth_login($user,$pass,$sticky=false){ 106 global $USERINFO; 107 global $conf; 108 global $lang; 109 global $auth; 110 $sticky ? $sticky = true : $sticky = false; //sanity check 111 112 if(isset($user)){ 113 //usual login 114 if ($auth->checkPass($user,$pass)){ 115 // make logininfo globally available 116 $_SERVER['REMOTE_USER'] = $user; 117 $USERINFO = $auth->getUserData($user); //FIXME move all references to session 118 119 // set cookie 120 $pass = PMA_blowfish_encrypt($pass,auth_cookiesalt()); 121 $cookie = base64_encode("$user|$sticky|$pass"); 122 if($sticky) $time = time()+60*60*24*365; //one year 123 setcookie(DOKU_COOKIE,$cookie,$time,'/'); 124 125 // set session 126 $_SESSION[$conf['title']]['auth']['user'] = $user; 127 $_SESSION[$conf['title']]['auth']['pass'] = $pass; 128 $_SESSION[$conf['title']]['auth']['buid'] = auth_browseruid(); 129 $_SESSION[$conf['title']]['auth']['info'] = $USERINFO; 130 return true; 131 }else{ 132 //invalid credentials - log off 133 msg($lang['badlogin'],-1); 134 auth_logoff(); 135 return false; 136 } 137 }else{ 138 // read cookie information 139 $cookie = base64_decode($_COOKIE[DOKU_COOKIE]); 140 list($user,$sticky,$pass) = split('\|',$cookie,3); 141 // get session info 142 $session = $_SESSION[$conf['title']]['auth']; 143 144 if($user && $pass){ 145 // we got a cookie - see if we can trust it 146 if(isset($session) && 147 ($session['user'] == $user) && 148 ($session['pass'] == $pass) && //still crypted 149 ($session['buid'] == auth_browseruid()) ){ 150 // he has session, cookie and browser right - let him in 151 $_SERVER['REMOTE_USER'] = $user; 152 $USERINFO = $session['info']; //FIXME move all references to session 153 return true; 154 } 155 // no we don't trust it yet - recheck pass 156 $pass = PMA_blowfish_decrypt($pass,auth_cookiesalt()); 157 return auth_login($user,$pass,$sticky); 158 } 159 } 160 //just to be sure 161 auth_logoff(); 162 return false; 163} 164 165/** 166 * Builds a pseudo UID from browser and IP data 167 * 168 * This is neither unique nor unfakable - still it adds some 169 * security. Using the first part of the IP makes sure 170 * proxy farms like AOLs are stil okay. 171 * 172 * @author Andreas Gohr <andi@splitbrain.org> 173 * 174 * @return string a MD5 sum of various browser headers 175 */ 176function auth_browseruid(){ 177 $uid = ''; 178 $uid .= $_SERVER['HTTP_USER_AGENT']; 179 $uid .= $_SERVER['HTTP_ACCEPT_ENCODING']; 180 $uid .= $_SERVER['HTTP_ACCEPT_LANGUAGE']; 181 $uid .= $_SERVER['HTTP_ACCEPT_CHARSET']; 182 $uid .= substr($_SERVER['REMOTE_ADDR'],0,strpos($_SERVER['REMOTE_ADDR'],'.')); 183 return md5($uid); 184} 185 186/** 187 * Creates a random key to encrypt the password in cookies 188 * 189 * This function tries to read the password for encrypting 190 * cookies from $conf['metadir'].'/_htcookiesalt' 191 * if no such file is found a random key is created and 192 * and stored in this file. 193 * 194 * @author Andreas Gohr <andi@splitbrain.org> 195 * 196 * @return string 197 */ 198function auth_cookiesalt(){ 199 global $conf; 200 $file = $conf['metadir'].'/_htcookiesalt'; 201 $salt = io_readFile($file); 202 if(empty($salt)){ 203 $salt = uniqid(rand(),true); 204 io_saveFile($file,$salt); 205 } 206 return $salt; 207} 208 209/** 210 * This clears all authenticationdata and thus log the user 211 * off 212 * 213 * @author Andreas Gohr <andi@splitbrain.org> 214 */ 215function auth_logoff(){ 216 global $conf; 217 global $USERINFO; 218 global $INFO, $ID; 219 global $auth; 220 221 if(isset($_SESSION[$conf['title']]['auth']['user'])) 222 unset($_SESSION[$conf['title']]['auth']['user']); 223 if(isset($_SESSION[$conf['title']]['auth']['pass'])) 224 unset($_SESSION[$conf['title']]['auth']['pass']); 225 if(isset($_SESSION[$conf['title']]['auth']['info'])) 226 unset($_SESSION[$conf['title']]['auth']['info']); 227 if(isset($_SERVER['REMOTE_USER'])) 228 unset($_SERVER['REMOTE_USER']); 229 $USERINFO=null; //FIXME 230 setcookie(DOKU_COOKIE,'',time()-600000,'/'); 231 232 if($auth && $auth->canDo('logoff')){ 233 $auth->logOff(); 234 } 235} 236 237/** 238 * Convinience function for auth_aclcheck() 239 * 240 * This checks the permissions for the current user 241 * 242 * @author Andreas Gohr <andi@splitbrain.org> 243 * 244 * @param string $id page ID 245 * @return int permission level 246 */ 247function auth_quickaclcheck($id){ 248 global $conf; 249 global $USERINFO; 250 # if no ACL is used always return upload rights 251 if(!$conf['useacl']) return AUTH_UPLOAD; 252 return auth_aclcheck($id,$_SERVER['REMOTE_USER'],$USERINFO['grps']); 253} 254 255/** 256 * Returns the maximum rights a user has for 257 * the given ID or its namespace 258 * 259 * @author Andreas Gohr <andi@splitbrain.org> 260 * 261 * @param string $id page ID 262 * @param string $user Username 263 * @param array $groups Array of groups the user is in 264 * @return int permission level 265 */ 266function auth_aclcheck($id,$user,$groups){ 267 global $conf; 268 global $AUTH_ACL; 269 270 # if no ACL is used always return upload rights 271 if(!$conf['useacl']) return AUTH_UPLOAD; 272 273 $user = auth_nameencode($user); 274 275 //if user is superuser return 255 (acl_admin) 276 if(auth_nameencode($conf['superuser']) == $user) { return AUTH_ADMIN; } 277 278 //make sure groups is an array 279 if(!is_array($groups)) $groups = array(); 280 281 //prepend groups with @ and nameencode 282 $cnt = count($groups); 283 for($i=0; $i<$cnt; $i++){ 284 $groups[$i] = '@'.auth_nameencode($groups[$i]); 285 } 286 //if user is in superuser group return 255 (acl_admin) 287 if(in_array(auth_nameencode($conf['superuser'],true), $groups)) { return AUTH_ADMIN; } 288 289 $ns = getNS($id); 290 $perm = -1; 291 292 if($user){ 293 //add ALL group 294 $groups[] = '@ALL'; 295 //add User 296 $groups[] = $user; 297 //build regexp 298 $regexp = join('|',$groups); 299 }else{ 300 $regexp = '@ALL'; 301 } 302 303 //check exact match first 304 $matches = preg_grep('/^'.preg_quote($id,'/').'\s+('.$regexp.')\s+/',$AUTH_ACL); 305 if(count($matches)){ 306 foreach($matches as $match){ 307 $match = preg_replace('/#.*$/','',$match); //ignore comments 308 $acl = preg_split('/\s+/',$match); 309 if($acl[2] > AUTH_DELETE) $acl[2] = AUTH_DELETE; //no admins in the ACL! 310 if($acl[2] > $perm){ 311 $perm = $acl[2]; 312 } 313 } 314 if($perm > -1){ 315 //we had a match - return it 316 return $perm; 317 } 318 } 319 320 //still here? do the namespace checks 321 if($ns){ 322 $path = $ns.':\*'; 323 }else{ 324 $path = '\*'; //root document 325 } 326 327 do{ 328 $matches = preg_grep('/^'.$path.'\s+('.$regexp.')\s+/',$AUTH_ACL); 329 if(count($matches)){ 330 foreach($matches as $match){ 331 $match = preg_replace('/#.*$/','',$match); //ignore comments 332 $acl = preg_split('/\s+/',$match); 333 if($acl[2] > AUTH_DELETE) $acl[2] = AUTH_DELETE; //no admins in the ACL! 334 if($acl[2] > $perm){ 335 $perm = $acl[2]; 336 } 337 } 338 //we had a match - return it 339 return $perm; 340 } 341 342 //get next higher namespace 343 $ns = getNS($ns); 344 345 if($path != '\*'){ 346 $path = $ns.':\*'; 347 if($path == ':\*') $path = '\*'; 348 }else{ 349 //we did this already 350 //looks like there is something wrong with the ACL 351 //break here 352 msg('No ACL setup yet! Denying access to everyone.'); 353 return AUTH_NONE; 354 } 355 }while(1); //this should never loop endless 356 357 //still here? return no permissions 358 return AUTH_NONE; 359} 360 361/** 362 * Encode ASCII special chars 363 * 364 * Some auth backends allow special chars in their user and groupnames 365 * The special chars are encoded with this function. Only ASCII chars 366 * are encoded UTF-8 multibyte are left as is (different from usual 367 * urlencoding!). 368 * 369 * Decoding can be done with rawurldecode 370 * 371 * @author Andreas Gohr <gohr@cosmocode.de> 372 * @see rawurldecode() 373 */ 374function auth_nameencode($name,$skip_group=false){ 375 if($skip_group && $name{0} =='@'){ 376 return '@'.preg_replace('/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f])/e', 377 "'%'.dechex(ord('\\1'))",substr($name,1)); 378 }else{ 379 return preg_replace('/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f])/e', 380 "'%'.dechex(ord('\\1'))",$name); 381 } 382} 383 384/** 385 * Create a pronouncable password 386 * 387 * @author Andreas Gohr <andi@splitbrain.org> 388 * @link http://www.phpbuilder.com/annotate/message.php3?id=1014451 389 * 390 * @return string pronouncable password 391 */ 392function auth_pwgen(){ 393 $pw = ''; 394 $c = 'bcdfghjklmnprstvwz'; //consonants except hard to speak ones 395 $v = 'aeiou'; //vowels 396 $a = $c.$v; //both 397 398 //use two syllables... 399 for($i=0;$i < 2; $i++){ 400 $pw .= $c[rand(0, strlen($c)-1)]; 401 $pw .= $v[rand(0, strlen($v)-1)]; 402 $pw .= $a[rand(0, strlen($a)-1)]; 403 } 404 //... and add a nice number 405 $pw .= rand(10,99); 406 407 return $pw; 408} 409 410/** 411 * Sends a password to the given user 412 * 413 * @author Andreas Gohr <andi@splitbrain.org> 414 * 415 * @return bool true on success 416 */ 417function auth_sendPassword($user,$password){ 418 global $conf; 419 global $lang; 420 global $auth; 421 422 $hdrs = ''; 423 $userinfo = $auth->getUserData($user); 424 425 if(!$userinfo['mail']) return false; 426 427 $text = rawLocale('password'); 428 $text = str_replace('@DOKUWIKIURL@',DOKU_URL,$text); 429 $text = str_replace('@FULLNAME@',$userinfo['name'],$text); 430 $text = str_replace('@LOGIN@',$user,$text); 431 $text = str_replace('@PASSWORD@',$password,$text); 432 $text = str_replace('@TITLE@',$conf['title'],$text); 433 434 return mail_send($userinfo['name'].' <'.$userinfo['mail'].'>', 435 $lang['regpwmail'], 436 $text, 437 $conf['mailfrom']); 438} 439 440/** 441 * Register a new user 442 * 443 * This registers a new user - Data is read directly from $_POST 444 * 445 * @author Andreas Gohr <andi@splitbrain.org> 446 * 447 * @return bool true on success, false on any error 448 */ 449function register(){ 450 global $lang; 451 global $conf; 452 global $auth; 453 454 if(!$_POST['save']) return false; 455 if(!$auth->canDo('addUser')) return false; 456 457 //clean username 458 $_POST['login'] = preg_replace('/.*:/','',$_POST['login']); 459 $_POST['login'] = cleanID($_POST['login']); 460 //clean fullname and email 461 $_POST['fullname'] = trim(preg_replace('/[\x00-\x1f:<>&%]+/','',$_POST['fullname'])); 462 $_POST['email'] = trim(preg_replace('/[\x00-\x1f:<>&%]+/','',$_POST['email'])); 463 464 if( empty($_POST['login']) || 465 empty($_POST['fullname']) || 466 empty($_POST['email']) ){ 467 msg($lang['regmissing'],-1); 468 return false; 469 } 470 471 if ($conf['autopasswd']) { 472 $pass = auth_pwgen(); // automatically generate password 473 } elseif (empty($_POST['pass']) || 474 empty($_POST['passchk'])) { 475 msg($lang['regmissing'], -1); // complain about missing passwords 476 return false; 477 } elseif ($_POST['pass'] != $_POST['passchk']) { 478 msg($lang['regbadpass'], -1); // complain about misspelled passwords 479 return false; 480 } else { 481 $pass = $_POST['pass']; // accept checked and valid password 482 } 483 484 //check mail 485 if(!mail_isvalid($_POST['email'])){ 486 msg($lang['regbadmail'],-1); 487 return false; 488 } 489 490 //okay try to create the user 491 if(!$auth->createUser($_POST['login'],$pass,$_POST['fullname'],$_POST['email'])){ 492 msg($lang['reguexists'],-1); 493 return false; 494 } 495 496 if (!$conf['autopasswd']) { 497 msg($lang['regsuccess2'],1); 498 notify('', 'register', '', $_POST['login'], false); 499 return true; 500 } 501 502 // autogenerated password? then send him the password 503 if (auth_sendPassword($_POST['login'],$pass)){ 504 msg($lang['regsuccess'],1); 505 notify('', 'register', '', $_POST['login'], false); 506 return true; 507 }else{ 508 msg($lang['regmailfail'],-1); 509 return false; 510 } 511} 512 513/** 514 * Update user profile 515 * 516 * @author Christopher Smith <chris@jalakai.co.uk> 517 */ 518function updateprofile() { 519 global $conf; 520 global $INFO; 521 global $lang; 522 global $auth; 523 524 if(!$_POST['save']) return false; 525 526 // should not be able to get here without Profile being possible... 527 if(!$auth->canDo('Profile')) { 528 msg($lang['profna'],-1); 529 return false; 530 } 531 532 if ($_POST['newpass'] != $_POST['passchk']) { 533 msg($lang['regbadpass'], -1); // complain about misspelled passwords 534 return false; 535 } 536 537 //clean fullname and email 538 $_POST['fullname'] = trim(preg_replace('/[\x00-\x1f:<>&%]+/','',$_POST['fullname'])); 539 $_POST['email'] = trim(preg_replace('/[\x00-\x1f:<>&%]+/','',$_POST['email'])); 540 541 if (empty($_POST['fullname']) || empty($_POST['email'])) { 542 msg($lang['profnoempty'],-1); 543 return false; 544 } 545 546 if (!mail_isvalid($_POST['email'])){ 547 msg($lang['regbadmail'],-1); 548 return false; 549 } 550 551 if ($_POST['fullname'] != $INFO['userinfo']['name']) $changes['name'] = $_POST['fullname']; 552 if ($_POST['email'] != $INFO['userinfo']['mail']) $changes['mail'] = $_POST['email']; 553 if (!empty($_POST['newpass'])) $changes['pass'] = $_POST['newpass']; 554 555 if (!count($changes)) { 556 msg($lang['profnochange'], -1); 557 return false; 558 } 559 560 if ($conf['profileconfirm']) { 561 if (!auth_verifyPassword($_POST['oldpass'],$INFO['userinfo']['pass'])) { 562 msg($lang['badlogin'],-1); 563 return false; 564 } 565 } 566 567 return $auth->modifyUser($_SERVER['REMOTE_USER'], $changes); 568} 569 570/** 571 * Send a new password 572 * 573 * @author Benoit Chesneau <benoit@bchesneau.info> 574 * @author Chris Smith <chris@jalakai.co.uk> 575 * 576 * @return bool true on success, false on any error 577*/ 578function act_resendpwd(){ 579 global $lang; 580 global $conf; 581 global $auth; 582 583 if(!$_POST['save']) return false; 584 if(!actionOK('resendpwd')) return false; 585 586 // should not be able to get here without modPass being possible... 587 if(!$auth->canDo('modPass')) { 588 msg($lang['resendna'],-1); 589 return false; 590 } 591 592 if (empty($_POST['login'])) { 593 msg($lang['resendpwdmissing'], -1); 594 return false; 595 } else { 596 $user = $_POST['login']; 597 } 598 599 $userinfo = $auth->getUserData($user); 600 if(!$userinfo['mail']) { 601 msg($lang['resendpwdnouser'], -1); 602 return false; 603 } 604 605 $pass = auth_pwgen(); 606 if (!$auth->modifyUser($user,array('pass' => $pass))) { 607 msg('error modifying user data',-1); 608 return false; 609 } 610 611 if (auth_sendPassword($user,$pass)) { 612 msg($lang['resendpwdsuccess'],1); 613 } else { 614 msg($lang['regmailfail'],-1); 615 } 616 return true; 617} 618 619/** 620 * Uses a regular expresion to check if a given mail address is valid 621 * 622 * May not be completly RFC conform! 623 * 624 * @link http://www.webmasterworld.com/forum88/135.htm 625 * 626 * @param string $email the address to check 627 * @return bool true if address is valid 628 */ 629function isvalidemail($email){ 630 return eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$", $email); 631} 632 633/** 634 * Encrypts a password using the given method and salt 635 * 636 * If the selected method needs a salt and none was given, a random one 637 * is chosen. 638 * 639 * The following methods are understood: 640 * 641 * smd5 - Salted MD5 hashing 642 * md5 - Simple MD5 hashing 643 * sha1 - SHA1 hashing 644 * ssha - Salted SHA1 hashing 645 * crypt - Unix crypt 646 * mysql - MySQL password (old method) 647 * my411 - MySQL 4.1.1 password 648 * 649 * @author Andreas Gohr <andi@splitbrain.org> 650 * @return string The crypted password 651 */ 652function auth_cryptPassword($clear,$method='',$salt=''){ 653 global $conf; 654 if(empty($method)) $method = $conf['passcrypt']; 655 656 //prepare a salt 657 if(empty($salt)) $salt = md5(uniqid(rand(), true)); 658 659 switch(strtolower($method)){ 660 case 'smd5': 661 return crypt($clear,'$1$'.substr($salt,0,8).'$'); 662 case 'md5': 663 return md5($clear); 664 case 'sha1': 665 return sha1($clear); 666 case 'ssha': 667 $salt=substr($salt,0,4); 668 return '{SSHA}'.base64_encode(pack("H*", sha1($clear.$salt)).$salt); 669 case 'crypt': 670 return crypt($clear,substr($salt,0,2)); 671 case 'mysql': 672 //from http://www.php.net/mysql comment by <soren at byu dot edu> 673 $nr=0x50305735; 674 $nr2=0x12345671; 675 $add=7; 676 $charArr = preg_split("//", $clear); 677 foreach ($charArr as $char) { 678 if (($char == '') || ($char == ' ') || ($char == '\t')) continue; 679 $charVal = ord($char); 680 $nr ^= ((($nr & 63) + $add) * $charVal) + ($nr << 8); 681 $nr2 += ($nr2 << 8) ^ $nr; 682 $add += $charVal; 683 } 684 return sprintf("%08x%08x", ($nr & 0x7fffffff), ($nr2 & 0x7fffffff)); 685 case 'my411': 686 return '*'.sha1(pack("H*", sha1($clear))); 687 default: 688 msg("Unsupported crypt method $method",-1); 689 } 690} 691 692/** 693 * Verifies a cleartext password against a crypted hash 694 * 695 * The method and salt used for the crypted hash is determined automatically 696 * then the clear text password is crypted using the same method. If both hashs 697 * match true is is returned else false 698 * 699 * @author Andreas Gohr <andi@splitbrain.org> 700 * @return bool 701 */ 702function auth_verifyPassword($clear,$crypt){ 703 $method=''; 704 $salt=''; 705 706 //determine the used method and salt 707 $len = strlen($crypt); 708 if(substr($crypt,0,3) == '$1$'){ 709 $method = 'smd5'; 710 $salt = substr($crypt,3,8); 711 }elseif(substr($crypt,0,6) == '{SSHA}'){ 712 $method = 'ssha'; 713 $salt = substr(base64_decode(substr($crypt, 6)),20); 714 }elseif($len == 32){ 715 $method = 'md5'; 716 }elseif($len == 40){ 717 $method = 'sha1'; 718 }elseif($len == 16){ 719 $method = 'mysql'; 720 }elseif($len == 41 && $crypt[0] == '*'){ 721 $method = 'my411'; 722 }else{ 723 $method = 'crypt'; 724 $salt = substr($crypt,0,2); 725 } 726 727 //crypt and compare 728 if(auth_cryptPassword($clear,$method,$salt) === $crypt){ 729 return true; 730 } 731 return false; 732} 733 734//Setup VIM: ex: et ts=2 enc=utf-8 : 735