[ldap_passwd] Utilisation de la hashlib en lieu et place de md5 et sha
darcs-hash:20110227125935-ffbb2-bc18e97a03b502e327e917fe3613f908f5c89d85.gz
This commit is contained in:
parent
48770cda56
commit
273a1c29fa
1 changed files with 14 additions and 5 deletions
|
@ -49,7 +49,8 @@
|
||||||
import string,base64
|
import string,base64
|
||||||
import random,sys
|
import random,sys
|
||||||
import exceptions
|
import exceptions
|
||||||
import md5,sha,crypt
|
import crypt
|
||||||
|
import hashlib
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import smbpasswd
|
import smbpasswd
|
||||||
|
@ -92,13 +93,21 @@ def mkpasswd(pwd, sambaver=3, algo='SSHA', salt=None):
|
||||||
raise TypeError, 'Algorithm <%s> not supported in this version.' % algo
|
raise TypeError, 'Algorithm <%s> not supported in this version.' % algo
|
||||||
|
|
||||||
if algo == 'ssha':
|
if algo == 'ssha':
|
||||||
pwdhash = "{SSHA}" + base64.encodestring(sha.new(str(pwd) + salt).digest() + salt)
|
h = hashlib.sha1()
|
||||||
|
h.update(str(pwd) + salt)
|
||||||
|
pwdhash = "{SSHA}" + base64.encodestring(h.digest() + salt)
|
||||||
elif algo =='sha':
|
elif algo =='sha':
|
||||||
pwdhash = "{SHA}" + base64.encodestring(sha.new(str(pwd)).digest())
|
h = hashlib.sha1()
|
||||||
|
h.update(str(pwd))
|
||||||
|
pwdhash = "{SHA}" + base64.encodestring(h.digest())
|
||||||
elif algo =='md5':
|
elif algo =='md5':
|
||||||
pwdhash = "{MD5}" + base64.encodestring(md5.new(str(pwd)).digest())
|
h = hashlib.md5()
|
||||||
|
h.update(str(pwd))
|
||||||
|
pwdhash = "{MD5}" + base64.encodestring(h.digest())
|
||||||
elif algo == 'smd5':
|
elif algo == 'smd5':
|
||||||
pwdhash = "{SMD5}" + base64.encodestring(md5.new(str(pwd) + salt).digest() + salt)
|
h = hashlib.md5()
|
||||||
|
h.update(str(pwd) + salt)
|
||||||
|
pwdhash = "{SMD5}" + base64.encodestring(h.digest() + salt)
|
||||||
elif algo =='crypt':
|
elif algo =='crypt':
|
||||||
pwdhash = "{CRYPT}" + crypt.crypt(str(pwd),getsalt(length=2)) # crypt only uses a salt of length 2
|
pwdhash = "{CRYPT}" + crypt.crypt(str(pwd),getsalt(length=2)) # crypt only uses a salt of length 2
|
||||||
elif algo == 'lmpassword':
|
elif algo == 'lmpassword':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue