diff options
author | jazzyb <json.barnes@gmail.com> | 2015-02-05 13:20:52 -0500 |
---|---|---|
committer | Donald Stufft <donald@stufft.io> | 2015-06-12 16:55:05 -0400 |
commit | 5b7f6df7141d738c83120a217b208e43685391a9 (patch) | |
tree | 0b782b9ceaf63369a302add765992cdf8f3eef01 /src/bcrypt | |
parent | fe0835805f96539ca1ac737513bb019ddbbfee03 (diff) | |
download | py-bcrypt-git-5b7f6df7141d738c83120a217b208e43685391a9.tar.gz |
Add prefix option to gensalt() - default to "2b"
Diffstat (limited to 'src/bcrypt')
-rw-r--r-- | src/bcrypt/__init__.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/bcrypt/__init__.py b/src/bcrypt/__init__.py index 10f860b..f09db91 100644 --- a/src/bcrypt/__init__.py +++ b/src/bcrypt/__init__.py @@ -35,12 +35,15 @@ __all__ = [ ] -def gensalt(rounds=12): +def gensalt(rounds=12, prefix=b"2b"): + if prefix not in (b"2a", b"2b"): + raise ValueError("Supported prefixes are b'2a' or b'2b'") + salt = os.urandom(16) output = _bcrypt.ffi.new("unsigned char[]", 30) retval = _bcrypt.lib.crypt_gensalt_rn( - b"$2a$", rounds, salt, len(salt), output, len(output), + b"$" + prefix + b"$", rounds, salt, len(salt), output, len(output), ) if not retval: |