如何在Django LDAP登录名上应用哈希SHA256? - python

我正在Django中使用LDAP身份验证,如下所示,并且还使用了密码哈希。

from django_auth_ldap.config import PosixGroupType, LDAPSearch
import ldap

PASSWORD_HASHERS = [
    'django.contrib.auth.hashers.PBKDF2PasswordHasher',
    'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
    'django.contrib.auth.hashers.Argon2PasswordHasher',
    'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
]

# We use a dedicated user to bind to the LDAP server and execute the server.
AUTH_LDAP_SERVER_URI = "ldap://xx.xx.xx.xx:389"
AUTH_LDAP_BIND_DN = "[email protected]"
AUTH_LDAP_BIND_PASSWORD = "xxxxx"
AUTH_LDAP_CONNECTION_OPTIONS = {
    ldap.OPT_DEBUG_LEVEL: 1,
    ldap.OPT_REFERRALS: 0,
}

# sAMAccountName is mostly used for Micrsoft Active Directory
# objectCategory    CN=Person,CN=Schema,CN=Configuration,DC=corp,DC=xxxx,DC=com
# (cn=%(user)s)
AUTH_LDAP_USER_SEARCH = LDAPSearch("DC=corp,DC=xxxxx,DC=com", 
                                    ldap.SCOPE_SUBTREE, 
                                    "(&(objectClass=user)(sAMAccountName=%(user)s))")

AUTH_LDAP_USER_ATTR_MAP = {
    "first_name": "givenName",
    "last_name": "sn",
    "email": "mail"
}

但是,我的凭据是以纯文本格式传输的。

来自Fiddler:

如何在Django LDAP登录名上应用哈希SHA256? - python

密码存储在数据库中:

!Qoc6uEP5h0lOXIeqmSov1HWOL8eY4fmlpJ1Z3q

如何应用散列SHA256?

注意:站点已部署在Windows Server 2008 r2的Apache2.4上。

参考方案

如果您需要哈希密码,请尝试以下操作:

import hashlib
HashedPassword =hashlib.sha1('PASSWORD'.encode('UTF-8'))

如何在django views.py中获取选定选项的文本值 - python

例如:如果选择了第一个选项Regular,那么我如何在views.py中获取值“ 1”及其文本值“ Regular”<form method = "post" action = "{% url 'index' %}"> {% csrf_token %} <select name =…

如何在Django 2.1中实施新帖子的审核 - python

我是Django的新手。我写的是Django 2.1,Python 3.6。面临以下问题。我想审核新创建的帖子。也就是说,可以在管理面板中打勾,并且只有在发布之后才能发布。但是,当然,理想情况下,当然是这样,以便管理员可以在站点上直接看到新条目并允许它们在该位置发布。models.pyclass Post(models.Model): user = mode…

Python uuid4,如何限制唯一字符的长度 - python

在Python中,我正在使用uuid4()方法创建唯一的字符集。但是我找不到将其限制为10或8个字符的方法。有什么办法吗?uuid4()ffc69c1b-9d87-4c19-8dac-c09ca857e3fc谢谢。 参考方案 尝试:x = uuid4() str(x)[:8] 输出:"ffc69c1b" Is there a way to…

Django:没有名为context_processors的模块,基本URL - python

我在网上搜寻解决方案,但似乎无济于事。我收到错误消息:ImproperlyConfigured at /tool/page4/ Error importing module mysite.context_processors: "No module named context_processors" settings.pyTEMPLATE…

Python-crontab模块 - python

我正在尝试在Linux OS(CentOS 7)上使用Python-crontab模块我的配置文件如下:{ "ossConfigurationData": { "work1": [ { "cronInterval": "0 0 0 1 1 ?", "attribute&…