<p>现在我看到你的代码了,我知道密码是'Khs9',我可以登录到你的邮箱。</p>
<p>你可以私下运行以下命令。</p>
<pre><code>>>> crypt.crypt('Khs9', 'aa')
'aa0GPiClW35DQ
</code></pre>
<p>现在更新代码:</p>
<pre><code>import crypt
max_attempts = 3
attempt = 0
stored_pw_hash = 'aa0GPiClW35DQ'
try:
while attempt < max_attempts:
uname = input('Username: ')
entered_pw_hash = crypt.crypt(input('pass: '), stored_pw_hash)
if uname == 'admin' and entered_pw_hash == stored_pw_hash:
print('Welcome Admin')
break
else:
attempt += 1
if attempt == max_attempts:
raise RuntimeError("\nYou've reached the maximum number of attempts allowed.")
else:
print('Wrong credentials.\n Try again or press <ctrl+c> to exit.\n')
continue
except KeyboardInterrupt:
print('Terminated by the user.\nGood-bye.')
except RuntimeError as e:
print("Goodbye")
</code></pre>
<p>如果你的代码泄露了,他们就不能马上访问。你应该有足够的时间意识到你被黑客攻击,然后更改你的密码。</p>
<p>这是背景资料。。。</p>
<p>crypt.crypt(密码)将返回密码的哈希值。存储散列而不是明文密码。这样,你就不能因为没有密码就把密码丢给黑客。丢失散列不是大问题,因为它不能保证访问(如果遵循最佳实践,包括使用salt)。</p>
<p>下次有人提供密码时,你会计算出它的哈希值,并将其与之前存储的哈希值进行比较,如果它们匹配,你就会知道他们给了你正确的密码。</p>
<p>你为什么要用盐?
因为有人花了很长时间生成一个包含常用密码和散列的表。一旦完成,这是一个快速检查破解杂凑。通过使用salt,您可以确保应用不同的查找表,一个可能不可用的查找表,并且普通黑客没有时间生成它。</p>
<p>crypt.crypt()需要两个字符才能用作盐。可以向它传递一个两个字符的字符串,也可以使用函数的前一个输出。(crypt.crypt()返回一个字符串,前两个字符是salt,其余字符是hash)</p>
<p>我看着<a href="https://docs.python.org/3.4/library/crypt.html" rel="nofollow">https://docs.python.org/3.4/library/crypt.html</a>回答这个问题。</p>