mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-06 18:00:57 +00:00
feat: 用户密码 hash 采用 gmsm3
This commit is contained in:
23
apps/common/hashers/sm3.py
Normal file
23
apps/common/hashers/sm3.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from gmssl import sm3, func
|
||||
|
||||
from django.contrib.auth.hashers import PBKDF2PasswordHasher
|
||||
|
||||
|
||||
class Hasher:
|
||||
name = 'sm3'
|
||||
|
||||
def __init__(self, key):
|
||||
self.key = key
|
||||
|
||||
def hexdigest(self):
|
||||
return sm3.sm3_hash(func.bytes_to_list(self.key))
|
||||
|
||||
@staticmethod
|
||||
def hash(msg):
|
||||
return Hasher(msg)
|
||||
|
||||
|
||||
class PBKDF2SM3PasswordHasher(PBKDF2PasswordHasher):
|
||||
algorithm = "pbkdf2_sm3"
|
||||
digest = Hasher.hash
|
||||
|
Reference in New Issue
Block a user