質問

なんと、通常のpythonライブラリを助けてくれを認証方式のためのデスクトップアプリいきます。いつの方法ではウェブフレームワークなどのdjangoはturbogears.

どんな種類のユーザ名-パスワード協会に格納され地元のファイルです。私は書くことができるが、私は既に存在するときより良いソリューション(私はあまりに堪能な暗号化).

役に立ちましたか?

解決

治療として以下の擬似コードの..

try:
    from hashlib import sha as hasher
except ImportError:
    # You could probably exclude the try/except bit,
    # but older Python distros dont have hashlib.
    try:
        import sha as hasher
    except ImportError:
        import md5 as hasher


def hash_password(password):
    """Returns the hashed version of a string
    """
    return hasher.new( str(password) ).hexdigest()

def load_auth_file(path):
    """Loads a comma-seperated file.
    Important: make sure the username
    doesn't contain any commas!
    """
    # Open the file, or return an empty auth list.
    try:
        f = open(path)
    except IOError:
        print "Warning: auth file not found"
        return {}

    ret = {}
    for line in f.readlines():
        split_line = line.split(",")
        if len(split_line) > 2:
            print "Warning: Malformed line:"
            print split_line
            continue # skip it..
        else:
            username, password = split_line
            ret[username] = password
        #end if
    #end for
    return ret

def main():
    auth_file = "/home/blah/.myauth.txt"
    u = raw_input("Username:")
    p = raw_input("Password:") # getpass is probably better..
    if auth_file.has_key(u.strip()):
        if auth_file[u] == hash_password(p):
            # The hash matches the stored one
            print "Welcome, sir!"

の代わりにカンマで区切られたファイルは、使用をお勧めしSQLite3(される可能性のあるその他の設定です。

また、覚えていることなセキュリティがある場合、アプリケーションが悪ユーザーがするとともに置き換え ~/.myauth.txt ファイル..プローブを用authが難しいのです。できない暗号化データで読み込み用ユーザーのパスワードは、一般的には非常に注意した方が良いと思います。

他のヒント

dbrは言った:

def hash_password(password):
    """Returns the hashed version of a string
    """
    return hasher.new( str(password) ).hexdigest()

これは本当に不安をハッシュパスワードをす いのではないかと思います。したい場合なぜそうなの読み込み Bycrypt紙 のだったのパスワードハッシュシステムOpenBSD.またまた良いかの議論のパスワードはチェック インタビュー の著者の切り裂きジャック(大人気のunixパスワードをクラッカー).

今B-納骨堂には観光スポットを表示一部の観光いっご使用にならないでください。システムgoogle moderatorのhelpを和訳してみましたのEKS-Blowfishアルゴリズムで利用可能なプロジェクトを実施する私。私は若干のバージョンアップ版FreeBSDシステムの今後ます。の概要はこちら。だけではなくハッシュのパスワードになります。塩のパスワードをハッシュパスワードを繰り返10,000います。

そのなこちらのコード:

#note I am using the Python Cryptography Toolkit
from Crypto.Hash import SHA256

HASH_REPS = 50000

def __saltedhash(string, salt):
    sha256 = SHA256.new()
    sha256.update(string)
    sha256.update(salt)
    for x in xrange(HASH_REPS): 
        sha256.update(sha256.digest())
        if x % 10: sha256.update(salt)
    return sha256

def saltedhash_bin(string, salt):
    """returns the hash in binary format"""
    return __saltedhash(string, salt).digest()

def saltedhash_hex(string, salt):
    """returns the hash in hex format"""
    return __saltedhash(string, salt).hexdigest()

導入に向けたシステムのようにこのキーのことを考えるのHASH_REPS定数です。この拡張性のコスト要因があります。う必要がありま試験を得るためのexceptable量たい時にいつでもお待ちごハッシュ計算されることのリスクオフライン辞書に基づく攻撃パスワードファイルです。

セキュリティがハードの方法やっていない最善の方法ですが大幅により簡単なハッシュ.また、ドライバーが必死に車を止ます。ですから、より複雑な溶液な最悪のがあります。

武器agiは、dexで下がらないboxerぐ, Tim

さん応援ありがとうございまご自身の認証方式としていなかったということではないかせる応用が図書館での暗号化など pycrypto その他の軽量化により図書館があります。

ちなみが必要な場合windowsバイナリのためのpycryptoします こちらの

したい場合は、その利用辞書のキーは、ユーザ名との値のパスワード(暗号化されたというSHA256). 漬け ですからディスクとしてこのデスクトップアプリケーショ私としてのオーバーヘッドなメモリはごくわずかである).

例えば:

import pickle
import hashlib

# Load from disk
pwd_file = "mypasswords"
if os.path.exists(pwd_file):
    pwds = pickle.load(open(pwd_file, "rb"))
else:
    pwds = {}

# Save to disk
pickle.dump(pwds, open(pwd_file, "wb"))

# Add password
pwds[username] = hashlib.sha256(password).hexdigest()

# Check password
if pwds[username] = hashlib.sha256(password).hexdigest():
   print "Good"
else:
   print "No match"

この店舗のパスワードとして ハッシュ -その本質的に復元できない.体を万が一紛失してしまった場合、パスワードがうまく割り当て新しいものは得します。

import hashlib
import random

def gen_salt():
    salt_seed = str(random.getrandbits(128))
    salt = hashlib.sha256(salt_seed).hexdigest()
    return salt

def hash_password(password, salt):
    h = hashlib.sha256()
    h.update(salt)
    h.update(password)
    return h.hexdigest()

#in datastore
password_stored_hash = "41e2282a9c18a6c051a0636d369ad2d4727f8c70f7ddeebd11e6f49d9e6ba13c"
salt_stored = "fcc64c0c2bc30156f79c9bdcabfadcd71030775823cb993f11a4e6b01f9632c3"

password_supplied = 'password'

password_supplied_hash = hash_password(password_supplied, salt_stored)
authenticated = (password_supplied_hash == password_stored_hash)
print authenticated #True

参照 gae-認証-a-3パーティサイト

利用"md5"あります。base64

>>> import md5
>>> hh = md5.new()
>>> hh.update('anoop')
>>> hh.digest
<built-in method digest of _hashlib.HASH object at 0x01FE1E40>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top