<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

//namespace userClass;

/**
 * Description of userClass
 *
 * @author Stagiaire
 */
class userClass {
  /**
   * @var bool true if ldap connection is valid
   */
  private $adCnx=false;
  
  /**
   * isValid : test credentials 
   * 
   * @var string $Usr User account (administrator or administrator@domain )
   * @var string $Pwd User password 
   */
  public function isValid($Cfg, $Usr, $Pwd)
  {
    if( $this->adCnx === false )
    { // No connection to ad yet
      $ad = new ldapClass();
      // Connect to server
      if( $ad->Connect($Cfg['uri']) === false ){
        return false;
      }
      if( ! $ad->bindWithCreds($Usr, $Pwd) ){
        return false;
      }
      return true;
    }
  }

}
