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
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue