Back to index

python-bcrypt  0.2
__init__.py
Go to the documentation of this file.
00001 """OpenBSD Blowfish password hashing.
00002 
00003 This module implements the OpenBSD Blowfish password hashing
00004 algorithm, as described in "A Future-Adaptable Password Scheme" by
00005 Niels Provos and David Mazieres.
00006 
00007 This system hashes passwords using a version of Bruce Schneier's
00008 Blowfish block cipher with modifications designed to raise the cost
00009 of off-line password cracking. The computation cost of the algorithm
00010 is parametised, so it can be increased as computers get faster.
00011 
00012 Passwords are hashed using the hashpw() routine:
00013 
00014   hashpw(password, salt) -> hashed_password
00015 
00016 Salts for the the second parameter may be randomly generated using the
00017 gensalt() function:
00018 
00019   gensalt(log_rounds = 12) -> random_salt
00020 
00021 The parameter "log_rounds" defines the complexity of the hashing. The
00022 cost increases as 2**log_rounds.
00023 """
00024 
00025 import os
00026 from _bcrypt import *
00027 
00028 def gensalt(log_rounds = 12):
00029        """Generate a random text salt for use with hashpw(). "log_rounds"
00030        defines the complexity of the hashing, increasing the cost as
00031        2**log_rounds."""
00032        return encode_salt(os.urandom(16), min(max(log_rounds, 4), 31))
00033