From 8968833003f1ee600e3e66dead9a0a49ca9e7da5 Mon Sep 17 00:00:00 2001 From: Jay Lee Date: Fri, 7 Feb 2020 12:59:51 -0500 Subject: [PATCH] crypt fix --- src/gam.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/gam.py b/src/gam.py index ecc96a24..b41f8818 100755 --- a/src/gam.py +++ b/src/gam.py @@ -54,7 +54,7 @@ from multiprocessing import set_start_method as mp_set_start_method from urllib.parse import quote, urlencode, urlparse if platform.system() == 'Windows': # No crypt module on Win, use passlib - from passlib.hash import sha512_crypt as crypt + from passlib.hash import sha512_crypt else: from crypt import crypt import dateutil.parser @@ -1516,6 +1516,12 @@ def addDelegates(users, i): print("Giving %s delegate access to %s (%s/%s)" % (delegate, delegator, i, count)) gapi.call(gmail.users().settings().delegates(), 'create', soft_errors=True, userId='me', body={'delegateEmail': delegate}) +def gen_sha512_hash(password): + if platform.system() == 'Windows': + return sha512_crypt.hash(password, rounds=5000) + else: + return crypt.crypt(password) + def printShowDelegates(users, csvFormat): if csvFormat: todrive = False @@ -7297,7 +7303,7 @@ def getUserAttributes(i, cd, updateCmd): rnd = SystemRandom() body['password'] = ''.join(rnd.choice(PASSWORD_SAFE_CHARS) for _ in range(100)) if 'password' in body and need_to_hash_password: - body['password'] = crypt(body['password']) + body['password'] = gen_sha512_hash(body['password']) body['hashFunction'] = 'crypt' return body