summaryrefslogtreecommitdiff
path: root/src/bcrypt
diff options
context:
space:
mode:
authorjazzyb <json.barnes@gmail.com>2015-02-05 13:20:52 -0500
committerDonald Stufft <donald@stufft.io>2015-06-12 16:55:05 -0400
commit5b7f6df7141d738c83120a217b208e43685391a9 (patch)
tree0b782b9ceaf63369a302add765992cdf8f3eef01 /src/bcrypt
parentfe0835805f96539ca1ac737513bb019ddbbfee03 (diff)
downloadpy-bcrypt-git-5b7f6df7141d738c83120a217b208e43685391a9.tar.gz
Add prefix option to gensalt() - default to "2b"
Diffstat (limited to 'src/bcrypt')
-rw-r--r--src/bcrypt/__init__.py7
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: