如何通过OpenLdap使用Python ldap3验证用户和密码?

问题描述

对于django项目,我设计了一个不同的登录页面。这里的用户将通过openldap登录

我可以使用用户的uid id访问用户的完整信息,但是找不到如何验证密码。

是否需要对用户密码进行哈希处理并将其与ldap上的密码进行比较?还没有其他方法吗?谢谢

select datum,feiertag
bulk collect into tab_feiertage
from (
    /* calculate moveable feast */
    with hol as ( 
      select calc_holidays(TO_NUMBER(in_year1)) as ostern
      from   dual ) 

    /* Static holidays */
    select to_date('01.01.'||in_year1,'DD.MM.YYYY') as datum,'Neujahr'   as feiertag from hol union all
    select to_date('06.01.'||in_year1,'3kings'    as feiertag from hol union all
    select to_date('08.03.'||in_year1,'Fraut'     as feiertag from hol union all
    select to_date('01.05.'||in_year1,'Arbeit'    as feiertag from hol union all
    select to_date('15.08.'||in_year1,'Himmel'    as feiertag from hol union all
    select to_date('03.10.'||in_year1,'Deu'       as feiertag from hol union all
    select to_date('31.10.'||in_year1,'Refo'      as feiertag from hol union all
    select to_date('01.11.'||in_year1,'Aller'     as feiertag from hol union all
    select to_date('25.12.'||in_year1,'Wh1'       as feiertag from hol union all
    select to_date('26.12.'||in_year1,'Wh2'       as feiertag from hol union all
    
    /* Changing holidays */
    select ostern,'Ostern'   as feiertag from hol union all
    select ostern - INTERVAL  '2' DAY as datum,'Karf'     as feiertag from hol union all
    select ostern - INTERVAL  '3' DAY as datum,'Gruen'    as feiertag from hol union all
    select ostern + INTERVAL  '1' DAY as datum,'Osterm'   as feiertag from hol union all
    select ostern + INTERVAL '39' DAY as datum,'Chimmel'  as feiertag from hol union all
    select ostern + INTERVAL '49' DAY as datum,'Pfingsts' as feiertag from hol union all
    select ostern + INTERVAL '50' DAY as datum,'Pfingstm' as feiertag from hol union all
    select ostern + INTERVAL '60' DAY as datum,'Fronlei'  as feiertag from hol
);

解决方法

只是为了检查我使用的用户名和密码:

import ldap3
from ldap3.core.exceptions import LDAPException


def _ldap_login(username,password):
    try:
        with ldap3.Connection('enter_server',user=username,password=password) as conn:
            print(conn.result["description"]) # "success" if bind is ok
            return True
    except LDAPException:
        print('Unable to connect to LDAP server')
        return False

_ldap_login("enter_username","enter_password")

以下是用于展示如何使用 ldap330 code examplesTutorial: Introduction to ldap3

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...