=1)其中有一項(xiàng)密碼值通過(guò)驗(yàn)證,則表示通過(guò)ldap驗(yàn)證....">
您的位置:軟件測(cè)試 > 軟件項(xiàng)目管理 > 項(xiàng)目管理軟件 > 禪道項(xiàng)目管理軟件
給禪道用戶登陸函數(shù)成員,加入ldap驗(yàn)證
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2016/2/25 13:32:08 ] 推薦標(biāo)簽:項(xiàng)目管理軟件 項(xiàng)目管理

  在/module/user/ext/model里新建identify.php,代碼如下:
public function identify($account, $password)
{
if(!$account or !$password) return false;
/**
*ldap驗(yàn)證程序塊,其中目錄樹的uid可以取同一個(gè)值,只要返回的數(shù)組(count>=1)其中有一項(xiàng)密碼值通過(guò)驗(yàn)證,則表示通過(guò)ldap驗(yàn)證;
*系統(tǒng)則不在重復(fù)驗(yàn)證密碼,但還要驗(yàn)證用戶名,因?yàn)橐獧z查數(shù)據(jù)的完整性.
*----------------------------------------Start---------------------------------------------*/
$ldaphost="192.168.0.2";
$ldapport=389;
$ldapUid="cn=admin,dc=21com,dc=com";
$ldapPwd="318296";
$base_dn="dc=21com,dc=com";
$filter="uid=".$account;
$attributes=array("userPassword");
$ds=ldap_connect($ldaphost,$ldapport) or die(js::error($this->lang->user->loginFailed));
if($ds){
ldap_set_option ( $ds, LDAP_OPT_PROTOCOL_VERSION, 3 );
ldap_set_option ( $ds, LDAP_OPT_REFERRALS, 0 ); // Binding to ldap server
$bd = ldap_bind($ds, $ldapUid, $ldapPwd)  or die(js::error($this->lang->user->loginFailed));
$sr=ldap_search($ds, $base_dn, $filter,$attributes);
$count=ldap_count_entries($ds, $sr);
if($count>0){
$info=ldap_get_entries($ds, $sr);
$ispass=FALSE;
for($i=0;$i<$info['count'];$i++){
$arrpwd=$info[$i]['userpassword'];
if(in_array($password, $arrpwd)||in_array(md5($password), $arrpwd)){
$ispass=TRUE;
break;
}
}
if($ispass){//通過(guò)則進(jìn)入系統(tǒng)用戶名驗(yàn)證
$this->dao->update(TABLE_USER)->set('password')->eq(md5($password))->where('account')->eq($account)->exec();
}else{
die(js::error($this->lang->user->loginFailed));die(1);
}
}else{
die(js::error($this->lang->user->loginFailed));die(2);
}
ldap_unbind($ds);
}
ldap_close($ds);
/*-------------------------------------End------------------------------------------------*/
/* Get the user first. If $password length is 32, don't add the password condition.  */
$user = $this->dao->select('*')->from(TABLE_USER)
->where('account')->eq($account)
//->beginIF(strlen($password) < 32)->andWhere('password')->eq(md5($password))->fi()//不驗(yàn)證密碼
//->andWhere('deleted')->eq(0)//不驗(yàn)證用戶是否禁用
->fetch();
/* If the length of $password is 32 or 40, checking by the auth hash. */
if($user and strlen($password) == 32)
{
$hash = $this->session->rand ? md5($user->password . $this->session->rand) : $user->password;
$user = $password == $hash ? $user : '';
}
elseif($user and strlen($password) == 40)
{
$hash = sha1($user->account . $user->password . $user->last);
$user = $password == $hash ? $user : '';
}
if($user)
{
$ip   = $this->server->remove_addr;
$last = $this->server->request_time;
$this->dao->update(TABLE_USER)->set('visitsvisits = visits + 1')->set('ip')->eq($ip)->set('last')->eq($last)->where('account')->eq($account)->exec();
$user->last = date(DT_DATETIME1, $user->last);
}
return $user;
}
  有關(guān)禪道方法重寫的問(wèn)題請(qǐng)參照禪道插件說(shuō)明,下面有pdf。

軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd