Making compatible with deprecation of crypt module in python
This commit is contained in:
parent
3c9a0526b9
commit
a30f242cc8
3 changed files with 48 additions and 5 deletions
|
|
@ -15,6 +15,13 @@ from os import path
|
|||
from paramecio2.modules.admin import admin_app, t
|
||||
from paramecio2.libraries.sendmail import SendMail
|
||||
from paramecio2.libraries.formsutils import check_csrf
|
||||
from hmac import compare_digest as compare_hash
|
||||
|
||||
try:
|
||||
import crypt
|
||||
crypt_pass=True
|
||||
except:
|
||||
crypt_pass=False
|
||||
#import gettext
|
||||
|
||||
#_=pgettext(__file__)
|
||||
|
|
@ -190,6 +197,7 @@ def logout():
|
|||
def login():
|
||||
|
||||
#connection=WebModel.connection()
|
||||
new_crypt=False
|
||||
|
||||
user_admin=UserAdmin(g.connection)
|
||||
|
||||
|
|
@ -218,7 +226,21 @@ def login():
|
|||
|
||||
if arr_user and not check_login_tries():
|
||||
|
||||
if user_admin.fields['password'].verify(password, arr_user['password']):
|
||||
# Layer compatibility with old crypt password
|
||||
|
||||
check_pass=user_admin.fields['password'].verify(password, arr_user['password'])
|
||||
|
||||
if not check_pass:
|
||||
#check_pass=password_ok(password, arr_user['password'])
|
||||
try:
|
||||
check_pass=compare_hash(arr_user['password'], crypt.crypt(password, arr_user['password']))
|
||||
new_crypt=True
|
||||
except:
|
||||
print('Warning: python developers deleting unix crypt module support, you cannot use sha512 passwords.')
|
||||
check_pass=False
|
||||
pass
|
||||
|
||||
if check_pass:
|
||||
|
||||
if not arr_user['disabled']:
|
||||
|
||||
|
|
@ -275,6 +297,13 @@ def login():
|
|||
|
||||
if len(arr_update)>0:
|
||||
|
||||
if new_crypt:
|
||||
print('Changing password for %s to argon2' % arr_user['username'])
|
||||
|
||||
user_admin.fields['password'].protected=False
|
||||
|
||||
arr_update['password']=password
|
||||
|
||||
user_admin.set_conditions('WHERE id=%s', [arr_user['id']]).update(arr_update)
|
||||
|
||||
return resp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue