1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2025-06-30 07:11:09 +02:00

CI passing!

This commit is contained in:
Alexandre Iooss
2019-08-09 23:22:20 +02:00
parent d6e7a2b635
commit be96a61ff2
5 changed files with 12 additions and 11 deletions

View File

@ -17,14 +17,14 @@ ALGO_LEN = len(ALGO_NAME + "$")
DIGEST_LEN = 20
def makeSecret(password):
def make_secret(password):
salt = os.urandom(4)
h = hashlib.sha1(password.encode())
h.update(salt)
return ALGO_NAME + "$" + encodestring(h.digest() + salt).decode()[:-1]
def checkPassword(challenge_password, password):
def check_password(challenge_password, password):
challenge_bytes = decodestring(challenge_password[ALGO_LEN:].encode())
digest = challenge_bytes[:DIGEST_LEN]
salt = challenge_bytes[DIGEST_LEN:]
@ -52,14 +52,14 @@ class SSHAPasswordHasher(hashers.BasePasswordHasher):
salt is overridden
"""
assert password is not None
return makeSecret(password)
return make_secret(password)
def verify(self, password, encoded):
"""
Check password against encoded using SSHA algorithm
"""
assert encoded.startswith(self.algorithm)
return checkPassword(encoded, password)
return check_password(encoded, password)
def safe_summary(self, encoded):
"""