Making compatible with deprecation of crypt module in python

This commit is contained in:
absurdo 2024-01-24 00:31:20 +01:00
parent 3c9a0526b9
commit a30f242cc8
3 changed files with 48 additions and 5 deletions

View file

@ -20,7 +20,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
from paramecio2.libraries.db.corefields import PhangoField
from paramecio2.libraries.db.coreforms import PasswordForm
from hmac import compare_digest as compare_hash
import crypt
#try:
# import crypt
#except:
# pass
#import bcrypt
from argon2 import PasswordHasher
class PasswordField(PhangoField):
"""Field for check and save passwords"""
@ -63,7 +69,10 @@ class PasswordField(PhangoField):
#salt=crypt.mksalt(crypt.METHOD_SHA512)
if self.encrypt_password:
value=crypt.crypt(value)
#value=crypt.crypt(value)
ph=PasswordHasher()
final_value=ph.hash(value)
return final_value
"""
else:
@ -79,7 +88,12 @@ class PasswordField(PhangoField):
def verify( password, h):
"""Static method used for verify a password save using PasswordField"""
#return bcrypt_sha256.verify(password, h)
return compare_hash(h, crypt.crypt(password, h))
#return compare_hash(h, crypt.crypt(password, h))
ph=PasswordHasher()
try:
return ph.verify(h, password)
except:
return False
# Old function bcrypt