def encoded_password(self):
if self.auth_method == Authentication.CLEARTEXT_PASSWORD:
return self.password
elif self.auth_method == Authentication.CRYPT_PASSWORD:
return crypt.crypt(self.password, self.options['salt'])
elif self.auth_method == Authentication.MD5_PASSWORD:
for key in 'user', 'salt':
m = hashlib.md5()
m.update(self.password + self.options[key])
hexdigest = m.hexdigest()
if six.PY3:
# In python3 the output of m.hexdigest() is a unicode string,
# so has to be converted to bytes before concat'ing with
# the password bytes.
hexdigest = bytes(hexdigest, 'ascii')
self.password = hexdigest
prefix = 'md5'
if six.PY3:
# Same workaround for bytes here.
prefix = bytes(prefix, 'ascii')
return prefix + self.password
else:
raise ValueError("unsupported authentication method: {0}".format(self.auth_method))
评论列表
文章目录