From: Michael Tremer Date: Thu, 13 Oct 2022 08:40:32 +0000 (+0000) Subject: builders: Drop unused password hashing functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a6a50ce9205f67afce549443436b9d0f82bcfc36;p=pbs.git builders: Drop unused password hashing functions Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/builders.py b/src/buildservice/builders.py index 415e053d..1718ebea 100644 --- a/src/buildservice/builders.py +++ b/src/buildservice/builders.py @@ -1,16 +1,11 @@ -#!/usr/bin/python +#!/usr/bin/python3 import asyncio import botocore.exceptions import datetime -import hashlib import logging -import random -import string -import time from . import base -from . import misc from .decorators import * @@ -632,42 +627,3 @@ class Builder(base.DataObject): ) return res.t - - -def generate_password_hash(password, salt=None, algo="sha512"): - """ - This function creates a salted digest of the given password. - """ - # Generate the salt (length = 16) of none was given. - if salt is None: - salt = misc.generate_random_string(length=16) - - # Compute the hash. - # + - if not algo in hashlib.algorithms: - raise Exception("Unsupported password hash algorithm: %s" % algo) - - # Calculate the digest. - h = hashlib.new(algo) - h.update(salt) - h.update(password) - - # Output string is of kind "$$". - return "$".join((algo, salt, h.hexdigest())) - -def check_password_hash(password, password_hash): - """ - Check a plain-text password with the given digest. - """ - # Handle plaintext passwords (plain$). - if password_hash.startswith("plain$"): - return password_hash[6:] == password - - try: - algo, salt, digest = password_hash.split("$", 2) - except ValueError: - logging.warning("Unknown password hash: %s" % password_hash) - return False - - # Re-generate the password hash and compare the result. - return password_hash == generate_password_hash(password, salt=salt, algo=algo)