password.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:hackathon 作者: vertica 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号