TypeError:encode()缺少1个必需的位置参数:'iterations'

时间:2017-10-23 16:37:07

标签: python django hash iteration encode

我不知道是什么触发了这个错误。我不知道为什么我一直得到这个错误。我已经更改了一些代码部分,但仍然出现此错误。我一直试图修复它2天。

回溯:

File "C:\Users\Adila\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\handlers\exception.py" in inner
  41.             response = get_response(request)

File "C:\Users\Adila\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\handlers\base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "C:\Users\Adila\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\handlers\base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\Adila\Documents\tryFOUR\src\register\views.py" in register
  13.           user = form.save()

File "C:\Users\Adila\Documents\tryFOUR\src\custom_user\forms.py" in save
  50.       user.set_password(self.cleaned_data["password2"])

File "C:\Users\Adila\AppData\Local\Programs\Python\Python35\lib\site-packages\django\contrib\auth\base_user.py" in set_password
  105.         self.password = make_password(raw_password)

File "C:\Users\Adila\AppData\Local\Programs\Python\Python35\lib\site-packages\django\contrib\auth\hashers.py" in make_password
  84.     return hasher.encode(password, salt)

Exception Type: TypeError at /accounts/register/
Exception Value: encode() missing 1 required positional argument: 'iterations'

hashers.py:

from django.contrib.auth.hashers import PBKDF2PasswordHasher
from django.utils.crypto import (get_random_string, pbkdf2)
from honeywordHasher.models import Sweetwords

class MyHoneywordHasher(PBKDF2PasswordHasher):
    algorithm = "honeyword_base9_tweak3_pbkdf2_sha256"
    iterations = PBKDF2PasswordHasher.iterations*3

    def hash(self, password, salt, iterations):
        hash = pbkdf2(password, salt, iterations, digest=self.digest)
        return base64.b64encode(hash).decode('ascii').strip()

    def salt(self):
        salt = get_random_string()
        while Sweetwords.objects.filter(salt=salt).exists():
            salt = get_random_string()

        return salt 

    def verify(self, password, encoded):
        algorithm, iterations, salt, dummy=encoded.split('$',3)
        hashes = pickle.loads(Sweetwords.objects.get(salt=salt).sweetwords)
        hash = self.hash(password, salt, int(iterations))
        if hash in hashes:
            return honeychecker.check_index(salt, hashes.index(hash))
        return False

    def encode(self, password, salt, iterations):
        sweetwords = ['hilman95']
        sweetwords.extend(honey_gen.gen(password, base64, ["passfiles.txt"]))
        for i in range(base64 + 1):
            sweetwords.extend(honeywordtweak.tweak(password[i], 3))
            random.shuffle(sweetwords)

        hashes = []
        for swd in sweetwords:
            hashes.append(self.hash(swd, salt, iterations))
        self.honeychecker.update_index(salt, sweetwords.index(password))
        h = Sweetwords(salt=salt, sweetwords = pickle.dumps(hashes))
        h.save()
        return "%s$%d$%s$%s" %(self.algorithm, iterations, salt, hashes[0])

有人可以解释为什么我一直收到这个错误吗?我花了几个小时在这里搜索所有相关的问题,没有解决它。

1 个答案:

答案 0 :(得分:0)

=JOIN(CHAR(10),FILTER(A1:A4,A1:A4<>""))