【发布时间】:2017-10-15 19:49:47
【问题描述】:
我正在实现一个密码生成器,它根据服务名称和主密码创建密码。为此,主密码和服务被散列。现在我只有小写字母和数字。我怎么还能包含大写字母和特殊符号?
我找到了以下代码,似乎可以解决问题。我应该使用它吗?它到底有什么作用?
raw_hexdigest = make_password(plaintext, service)
# Convert the hexdigest into decimal
num = int(raw_hexdigest, 16)
# What base will we convert `num` into?
num_chars = len(alphabet)
# Build up the new password one "digit" at a time,
# up to a certain length
chars = []
while len(chars) < length:
num, idx = divmod(num, num_chars)
chars.append(alphabet[idx])
return ''.join(chars)
【问题讨论】:
标签: python security hash passwords