Proyecto

General

Perfil

« Anterior | Siguiente » 

Revisión 147

Cifrado de password SSHA

Ver diferencias:

controlies/trunk/Utils/Utils.py
string = string.replace("ñ","n").replace("Ñ","N")
return string
def generate_salt():
# Salt can be any length, but not more than about 37 characters
# because of limitations of the binascii module.
# 7 is what Netscape's example used and should be enough.
# All 256 characters are available.
from random import randrange
salt = ''
for n in range(7):
salt += chr(randrange(256))
return salt
def encrypt(password):
import sha
from binascii import b2a_base64
password = str(password)
salt = generate_salt()
return b2a_base64(sha.new(password + salt).digest() + salt)[:-1]
controlies/trunk/Plugins/Users.py
def add(self):
maxID = str(LdapUtils.getMaxID(self.ldap))
passwd = hashlib.sha1(self.password).hexdigest()
passwd = '{SSHA}' + Utils.encrypt(self.password)
attr = [
('objectclass', ['top','posixAccount','shadowAccount','person','inetOrgPerson']),
......
def modify(self):
passwd = hashlib.sha1(self.password).hexdigest()
attr = [
(ldap.MOD_REPLACE, 'cn', [self.name] ),
(ldap.MOD_REPLACE, 'employeenumber', [self.nif] ),
(ldap.MOD_REPLACE, 'sn', [self.surname] ),
(ldap.MOD_REPLACE, 'userpassword', [passwd])
(ldap.MOD_REPLACE, 'sn', [self.surname] )
]
if self.password!="":
passwd = '{SSHA}' + Utils.encrypt(self.password)
attr.append((ldap.MOD_REPLACE, 'userpassword', [passwd]))
print "entro: "+self.password
print attr
self.ldap.modify("uid="+self.user+",ou=People", attr)
# Get current groups

Exportar a: Unified diff