DatabaseAuth.class.php (797B)
1 <?php 2 3 namespace cms\auth; 4 5 use cms\base\Configuration; 6 use database\Database; 7 8 /** 9 * Authentifzierung über eine externe Datenbank. 10 * @author dankert 11 * 12 */ 13 class DatabaseAuth implements Auth 14 { 15 16 /** 17 * Login. 18 */ 19 public function login($user, $password, $token) 20 { 21 $authDbConf = Configuration::subset(['security','authdb']); 22 23 if (!$authDbConf->is('enable',true)) 24 return Auth::STATUS_FAILED; 25 26 $authdb = new Database($authDbConf); 27 28 $sql = $authdb->sql($authDbConf->get('sql')); 29 $algo = $authDbConf->get('hash_algo' ); 30 $sql->setString('username', $user); 31 $sql->setString('password', hash($algo, $password)); 32 $row = $sql->getRow(); 33 34 $authdb->disconnect(); 35 36 return $row ? Auth::STATUS_SUCCESS : Auth::STATUS_FAILED; 37 } 38 39 public function username() 40 { 41 return null; 42 } 43 44 }