使用python在Windows上创建兼容的ldap密码(md5crypt) [英] use python to create compatible ldap password (md5crypt) on windows

查看:332
本文介绍了使用python在Windows上创建兼容的ldap密码(md5crypt)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您知道如何在Windows上通过python创建与ldap兼容的密码(首选md5crypt)

Do you know how to create a ldap compatible password (preferred md5crypt) via python on Windows

我曾经在Linux中写过类似的东西,但是Windows上没有crypt模块

I used to write something like this in Linux but the crypt module is not present on Windows

char_set = string.ascii_uppercase + string.digits
salt = ''.join(random.sample(char_set,8))
salt = '$1$' + salt + '$'
pwd = "{CRYPT}" + crypt.crypt(str(old_password),salt)

推荐答案

Passlib python库包含所有crypt(3)算法的跨平台实现.特别是,它包含 ldap_md5_crypt ,听起来像是什么你要.使用方法如下(此代码将在Windows或Linux上运行):

The Passlib python library contains cross-platform implementations of all the crypt(3) algorithms. In particular, it contains ldap_md5_crypt, which sounds like exactly what you want. Here's how to use it (this code will work on windows or linux):

from passlib.hash import ldap_md5_crypt

#note salt generation is automatically handled
hash = ldap_md5_crypt.encrypt("password")

#hash will be similar to '{CRYPT}$1$wa6OLvW3$uzcIj2Puf3GcFDf2KztQN0'

#to verify a password...
valid = ldap_md5_crypt.verify("password", hash)


我应该注意,尽管MD5-Crypt得到了广泛支持(Linux,所有BSD,内部都在openssl中),但它并不是最强大的散列,确实是非常不安全的,应该尽可能避免.如果您想要与linux crypt()兼容的最强大的哈希,则可以使用SHA512-Crypt.它在内部添加了可变回合,以及对MD5-Crypt的一些其他改进.


I should note that while MD5-Crypt is widely supported (Linux, all the BSDs, internally in openssl), it's none-the-less not the strongest hash available really horribly insecure, and should be avoided if at all possible. If you want the strongest hash that's compatible with linux crypt(), SHA512-Crypt is probably the way to go. It adds variable rounds, as well as some other improvements over MD5-Crypt internally.

这篇关于使用python在Windows上创建兼容的ldap密码(md5crypt)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆