2012-01-06 73 views
2

我在想,如果這將是驗證的安全方法:Python的SHA512安全

theInput = raw_input("Enter password: ") 
theHashed = hashlib.sha512(theInput).hexdigest() 
if theHashed == "35211b890b19afebfabc3451f04d150f1423bcb54ff7d62095677d7af7560fcvb56c112e879288836cb506853516c5dbd1d779cfaedf4a2f6f6a303600c0c589": 
    print "Correct!" 

如果不是,有什麼事情我做,使之更安全?

回答

4

也許,只要有人不能讀取或修改您的代碼。

如果這是在一臺計算機上本地運行的程序,並且該文件以普通用戶無法更改的方式進行安裝,並且您知道沒有安裝鍵盤記錄程序,那麼也許沒關係。

即使用戶可以讀取這個文件,他們可以複製並修改其副本以刪除身份驗證步驟。

程序安全性是一個複雜而深刻的話題,不僅僅是散列算法的選擇。

2

Greg Hewgill的第一點值得強調。我剛剛發現 - 有些令我驚訝 - 在我的筆記本上,系統hashlib.py對全世界開放。因此,擊敗上述認證很簡單:

localhost-2:coding $ cat hashcrack.py 
class always_equal(object): 
    def __eq__(self, other): 
     return True 

class sha512(object): 
    def __init__(self, password): 
     pass 
    def hexdigest(self): 
     return always_equal() 
localhost-2:coding $ cat hashcrack.py >> /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py 
localhost-2:coding $ cat notsosecure.py 
import hashlib 
theInput = raw_input("Enter password: ") 
theHashed = hashlib.sha512(theInput).hexdigest() 
if theHashed == "35211b890b19afebfabc3451f04d150f1423bcb54ff7d62095677d7af7560fcvb56c112e879288836cb506853516c5dbd1d779cfaedf4a2f6f6a303600c0c589": 
    print "Correct!" 
localhost-2:coding $ python notsosecure.py 
Enter password: pwned 
Correct! 

試想想起來了,我甚至沒有需要作出新的SHA512類,在舊我可以簡單地monkeypatched hexdigest。

反正+1到,它不是在你的散列位的數量是占主導地位的安全隱患點..

+0

+1 for always always equal – 2013-03-03 16:09:46

2

使用import getpass然後theInput = getpass.getpass("Enter password: ")代替的raw_input()。