The code below is working fine when saving, but if I tried to authenticate the user using the plain saved password it doesn't authenticate? and when I manually change the password in phpldapadmin to MD5 and test the authentication its working.
- How can I encrypt the password to MD5 in python and saved it in LDAP?
- Is there a difference in MD5 encryption between PHP and Python?
def addUser(record):
connect = ldapConnect()
try:
dn = "cn="+record['cn']+",ou=users,dc=example,dc=com"
attrs = {
"objectclass" : ['inetOrgPerson'.encode('utf-8'),'posixAccount'.encode('utf-8'),'shadowAccount'.encode('utf-8')],
"uid" : [record['uid'].encode('utf-8')],
"cn" : [record['cn'].encode('utf-8')],
"sn" : [record['sn'].encode('utf-8')],
"givenName" : [record['givenName'].encode('utf-8')],
"displayName" : [record['displayName'].encode('utf-8')],
"uidNumber" : [record['uidNumber'].encode('utf-8')],
"gidnumber" : [record['gidnumber'].encode('utf-8')],
"homeDirectory" : [record['homeDirectory'].encode('utf-8')],
"userpassword" : [record['userpassword'].encode('utf-8')]
}
connect.add_s(dn, modlist.addModlist(attrs))
connect.unbind_s()
return True
except ldap.LDAPError:
connect.unbind_s()
return False