Skip to content

Commit 49bbb54

Browse files
committed
make use of compat
1 parent 7daf45f commit 49bbb54

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

mig/shared/compat.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ def _is_unicode(val):
5555
return (type(val) == _TYPE_UNICODE)
5656

5757

58+
def encode_unicode_string(unicode_string):
59+
"""Convert a unicode string value to bytes."""
60+
61+
return codecs.encode(unicode_string, 'utf8')
62+
63+
5864
def ensure_native_string(string_or_bytes):
5965
"""Given a supplied input which can be either a string or bytes
6066
return a representation providing string operations while ensuring that

mig/shared/pwcrypto.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import time
4545

4646
from mig.shared.base import force_utf8, mask_creds, string_snippet
47+
from mig.shared.compat import encode_unicode_string
4748
from mig.shared.defaults import keyword_auto, RESET_TOKEN_TTL
4849

4950

@@ -118,7 +119,7 @@ def best_crypt_salt(configuration):
118119
def make_hash(password, _urandom=urandom):
119120
"""Generate a random salt and return a new hash for the password."""
120121
salt = b64encode(_urandom(SALT_LENGTH))
121-
password_bytes = codecs.encode(password, 'utf8')
122+
password_bytes = encode_unicode_string(password)
122123
password_hashed = hashlib.pbkdf2_hmac(HASH_FUNCTION,
123124
password_bytes, salt,
124125
COST_FACTOR, KEY_LENGTH)

0 commit comments

Comments
 (0)