예제 #1
0
 def safe_summary(self, encoded):
     algorithm, salt, hsh = encoded.split('$')
     return OrderedDict([
         (_('algorithm'), algorithm),
         (_('salt'), mask_hash(salt, show=2)),
         (_('hash'), mask_hash(hsh)),
     ])
예제 #2
0
 def safe_summary(self, encoded):
     algorithm, salt, hash = encoded.split('$', 2)
     assert algorithm == self.algorithm
     return SortedDict([
         (_('algorithm'), algorithm),
         (_('salt'), mask_hash(salt, show=2)),
         (_('hash'), mask_hash(hash)),
     ])
예제 #3
0
파일: hashers.py 프로젝트: FatBallFish/CDC
 def safe_summary(self, encoded):
     algorithm, salt, hash = encoded.split('$', 2)
     assert algorithm == self.algorithm
     return {
         _('algorithm'): algorithm,
         _('salt'): mask_hash(salt, show=2),
         _('hash'): mask_hash(hash),
     }
예제 #4
0
 def safe_summary(self, encoded):
     algorithm, iterations, salt, hash = encoded.split('$', 3)
     return OrderedDict([
         ('algorithm', algorithm),
         ('iterations', iterations),
         ('salt', mask_hash(salt)),
         ('hash', mask_hash(hash)),
     ])
예제 #5
0
파일: hashers.py 프로젝트: UrLab/incubator
 def safe_summary(self, encoded):  # pragma: no cover
     algorithm, salt, hash = encoded.split('$', 3)
     assert algorithm == self.algorithm
     return OrderedDict([
         ('algorithm', algorithm),
         ('salt', mask_hash(salt)),
         ('hash', mask_hash(hash)),
     ])
예제 #6
0
 def safe_summary(self, encoded):
     salt, hashed, algorithm = HASH_COMPILED_REGEXP.search(encoded).groups()
     assert algorithm == self.algorithm
     return SortedDict([
         (_('algorithm'), algorithm),
         (_('salt'), hashers.mask_hash(salt, show=2)),
         (_('hash'), hashers.mask_hash(hashed)),
     ])
예제 #7
0
 def safe_summary(self, encoded):
     algorithm, hash, salt = encoded.split('$', 3)
     #assert len(encoded) == 65
     return SortedDict([
         (_('algorithm'), self.algorithm),
         (_('salt'), mask_hash(salt, show=2)),
         (_('hash'), mask_hash(hash)),
     ])
예제 #8
0
 def safe_summary(self, encoded):
     algorithm, iterations, salt, hash = encoded.split('$', 3)
     return OrderedDict([
         ('algorithm', algorithm),
         ('iterations', iterations),
         ('salt', mask_hash(salt)),
         ('hash', mask_hash(hash)),
     ])
예제 #9
0
파일: hashers.py 프로젝트: RestAuth/server
 def safe_summary(self, encoded):  # pragma: no cover
     algorithm, salt, hash = encoded.split('$', 3)
     assert algorithm == self.algorithm
     return OrderedDict([
         ('algorithm', algorithm),
         ('salt', mask_hash(salt)),
         ('hash', mask_hash(hash)),
     ])
예제 #10
0
파일: backends.py 프로젝트: runt18/kuma
 def safe_summary(self, encoded):
     algorithm, salt, hash = encoded.split('$', 2)
     assert algorithm == self.algorithm
     return collections.OrderedDict([
         (ugettext('algorithm'), algorithm),
         (ugettext('salt'), mask_hash(salt, show=2)),
         (ugettext('hash'), mask_hash(hash)),
     ])
예제 #11
0
 def safe_summary(self, encoded):
     algorithm, salt, hash = encoded.split("$", 2)
     assert algorithm == self.algorithm
     return OrderedDict([
         (_("algorithm"), algorithm),
         (_("salt"), mask_hash(salt, show=2)),
         (_("hash"), mask_hash(hash)),
     ])
예제 #12
0
파일: hashers.py 프로젝트: power-ops/cmdb
 def safe_summary(self, encoded):
     algorithm, iterations, salt, hash = encoded.split('$', 3)
     assert algorithm == self.algorithm
     return {
         _('algorithm'): algorithm,
         _('iterations'): iterations,
         _('salt'): mask_hash(salt),
         _('hash'): mask_hash(hash),
     }
예제 #13
0
 def safe_summary(self, encoded):
     algorithm, prefix, salt, hash = encoded.split('$')
     assert algorithm == self.algorithm
     return OrderedDict([
         (_('algorithm'), algorithm),
         (_('prefix'), prefix),
         (_('salt'), mask_hash(salt)),
         (_('hash'), mask_hash(hash)),
     ])
예제 #14
0
파일: hashers.py 프로젝트: adieu/authentic2
 def safe_summary(self, encoded):
     algorithm, iterations, salt, hash = encoded.split('$', 3)
     assert algorithm == self.algorithm
     return SortedDict([
         (_('algorithm'), algorithm),
         (_('iterations'), iterations),
         (_('salt'), hashers.mask_hash(salt)),
         (_('hash'), hashers.mask_hash(hash)),
     ])
예제 #15
0
 def safe_summary(self, encoded):
     algorithm, iterations, salt, hash = encoded.split('$', 3)
     assert algorithm == self.algorithm
     return OrderedDict([
         (_('algorithm'), algorithm),
         (_('iterations'), iterations),
         (_('salt'), mask_hash(salt)),
         (_('hash'), mask_hash(hash)),
     ])
예제 #16
0
 def safe_summary(self, encoded):
     parts =  encoded.split('$', 3)
     algorithm, code, salt, hash = encoded.split('$', 3)
     assert algorithm == self.algorithm
     return SortedDict([
         ('algorithm', algorithm),
         ('salt', mask_hash(salt, show=2)),
         ('hash', mask_hash(hash)),
     ])
예제 #17
0
 def safe_summary(self, encoded):
     Nlog2, r, p, salt, hash = self._parse(encoded)
     return OrderedDict([
         (_('algorithm'), self.algorithm),
         (_('N'), 2**Nlog2),
         (_('r'), r),
         (_('p'), p),
         (_('salt'), mask_hash(salt, show=2)),
         (_('hash'), mask_hash(hash)),
     ])
예제 #18
0
 def safe_summary(self, encoded):
     algorithm, empty, algostr, work_factor, data = encoded.split('$', 4)
     assert algorithm == self.algorithm
     data_pass, data_salt = data.split('%', 1)
     return SortedDict([
         (_('algorithm'), algorithm),
         (_('work factor'), work_factor),
         (_('salt'), mask_hash(data_pass)),
         (_('checksum'), mask_hash(data_salt)),
     ])
예제 #19
0
 def safe_summary(self, encoded):
     algorithm, empty, algostr, work_factor, data = encoded.split('$', 4)
     assert algorithm == self.algorithm
     salt, checksum = data[:22], data[22:]
     return OrderedDict([
         (_('algorithm'), algorithm),
         (_('work factor'), work_factor),
         (_('salt'), mask_hash(salt)),
         (_('checksum'), mask_hash(checksum)),
     ])
 def safe_summary(self, encoded):
     algorithm, sharenumber, iterations, salt, hash = encoded.split('$', 4)
     assert algorithm == self.algorithm
     return OrderedDict([
         (_('algorithm'), algorithm),
         (_('sharenumber'), sharenumber),
         (_('iterations'), iterations),
         (_('salt'), mask_hash(salt)),
         (_('hash'), mask_hash(hash)),
     ])
예제 #21
0
 def safe_summary(self, encoded):
     algorithm, remainder = encoded.split('$')
     iterations = self.get_iteration_count(remainder[0])
     salt = remainder[1:9]
     hash = remainder[9:]
     return OrderedDict([
         (_('algorithm'), algorithm),
         (_('iterations'), iterations),
         (_('salt'), mask_hash(salt)),
         (_('hash'), mask_hash(hash)),
     ])
예제 #22
0
    def safe_summary(self, encoded):
        """
        Returns a summary of safe values

        The result is a dictionary and will be used where the password field
        must be displayed to construct a safe representation of the password.
        """
        algorithm, salt, password_hash = encoded.split('$', 2)
        assert algorithm == self.algorithm
        return OrderedDict([
            ('algorithm', algorithm),
            ('salt', mask_hash(salt)),
            ('hash', mask_hash(password_hash)),
        ])
예제 #23
0
파일: auth.py 프로젝트: yopiti/authserver
    def safe_summary(self, encoded: str) -> Dict[str, str]:
        """
        Returns a summary of safe values

        The result is a dictionary and will be used where the password field
        must be displayed to construct a safe representation of the password.
        """
        roundcount, salt, hash = self._split_encoded(encoded)
        return OrderedDict([
            (_('algorithm'), self.algorithm),
            (_('iterations'), str(roundcount)),
            (_('salt'), hashers.mask_hash(salt)),
            (_('hash'), hashers.mask_hash(hash)),
        ])
예제 #24
0
파일: auth.py 프로젝트: hwkns/streisand
    def safe_summary(self, encoded):
        """
        Returns a summary of safe values

        The result is a dictionary and will be used where the password field
        must be displayed to construct a safe representation of the password.
        """
        algorithm, salt, password_hash = encoded.split('$', 2)
        assert algorithm == self.algorithm
        return OrderedDict([
            ('algorithm', algorithm),
            ('salt', mask_hash(salt)),
            ('hash', mask_hash(password_hash)),
        ])
예제 #25
0
    def safe_summary(self, hashed):
        """
        Returns a summary of safe values

        The result is a dictionary and will be used where the password field
        must be displayed to construct a safe representation of the password.
        """
        mcf, cost, data = hashed[1:].split('$', 4)
        salt, checksum = data[:22], data[22:]
        return OrderedDict([
            (_('algorithm'), self.algorithm),
            (_('work factor'), cost),
            (_('salt'), mask_hash(salt)),
            (_('checksum'), mask_hash(checksum)),
        ])
예제 #26
0
    def safe_summary(self, encoded):
        """
        Returns a summary of safe values

        The result is a dictionary and will be used where the password field
        must be displayed to construct a safe representation of the password.
        """
        algorithm, local_maxtime, salt, data = encoded.split('$', 3)
        assert algorithm == self.algorithm
        return SortedDict([
            (_('algorithm'), algorithm),
            (_('maxtime'), local_maxtime),
            (_('salt'), hashers.mask_hash(salt)),
            (_('checksum'), hashers.mask_hash(data)),
        ])
예제 #27
0
    def safe_summary(self, encoded):
        algorithm, hash = encoded.split('$', 1)
        assert algorithm == self.algorithm

        data = [(_('algorithm'), algorithm), ]
        to_append = []

        parsed = self.hasher.parsehash(self.to_orig(encoded))

        # pop known fields that should be at the end first:
        for name, mapping, mask in _SETTINGS_MAPPING:
            value = parsed.pop(name, None)

            if value is not None:
                if mask is not False:
                    try:
                        # value is an int in some rare cases:
                        value = mask_hash(str(value), show=mask)
                    except UnicodeDecodeError:
                        # Thrown if non-ascii bytes are in the hash
                        value = '%s%s' % ('?' * mask, '*' * (len(value) - mask))

                to_append.append((mapping, value))

        # parse any left-over fields:
        for key, value in parsed.items():
            data.append((_(key), value))

        return OrderedDict(data + to_append)
예제 #28
0
 def safe_summary(self, encoded):
     algorithm, pghash = encoded.split('$', 1)
     assert algorithm == self.algorithm
     return OrderedDict([
         (_('algorithm'), algorithm),
         (_('hash'), mask_hash(pghash)),
     ])
예제 #29
0
    def get_context_data(self, **context):
        user = self.request.user

        itermediate_secret = get_user_itermediate_secret(
            user=self.request.user)
        if itermediate_secret is None:
            itermediate_secret_length = None
            masked_secret = None
        else:
            itermediate_secret_length = len(itermediate_secret)
            masked_secret = mask_hash(hash=itermediate_secret,
                                      show=6,
                                      char="*")

        token_dt = user_get_datetime(
            user=user, encrypted_data=self.request.user.example_secret)

        context.update({
            'user': user,
            'has_permission': True,  # enable '{% block usertools %}'
            'opts': UserSecretsModel._meta,
            'example_secret': self.request.user.example_secret,
            'token_dt': token_dt,
            'masked_secret': masked_secret,
            'itermediate_secret_length': itermediate_secret_length,
        })
        return super().get_context_data(**context)
예제 #30
0
파일: views.py 프로젝트: codelieche/moocweb
    def post(self, request):
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            email = register_form.cleaned_data['email']
            ## 需要判断email是否存在
            if UserProfile.objects.filter(email=email):
                return render(request, 'register.html', {
                    'register_form': register_form,
                    'msg': 'Email已经注册,请更换'
                })

            pass_word = register_form.cleaned_data['password']
            user_profile = UserProfile()
            user_profile.username = email
            user_profile.email = email
            user_profile.password = mask_hash(pass_word)
            # user_profile.set_password(pass_word)
            # 点击邮箱中的激活链接,is_active才变成True
            user_profile.is_active = False
            user_profile.save()

            # 发送验证邮件
            send_register_email(email, "register")
            # login(request, user_profile)

            # 写入注册信息
            UserMessage.objects.create(user=user_profile.id,
                                       message="欢迎注册mooc在线")
            return render(request, 'login.html')

        else:
            return render(request, 'register.html',
                          {'register_form': register_form})
예제 #31
0
파일: hashers.py 프로젝트: MGXRace/website
 def safe_summary(self, encoded):
     assert encoded.startswith('sha256$$')
     hash_ = encoded[8:]
     return OrderedDict([
         (_('algorithm'), self.algorithm),
         (_('hash'), mask_hash(hash_)),
     ])
예제 #32
0
    def test_safe_summary(self):
        """
        safe_summary works on a newly encoded password
        """

        h = SCryptPasswordHasher()
        password = string.printable
        salt = h.salt()
        encoded = h.encode(password, salt)

        summary = h.safe_summary(encoded)
        self.assertEqual(summary['algorithm'], 'scrypt')
        self.assertEqual(summary['N'], 2**15)
        self.assertEqual(summary['r'], 8)
        self.assertEqual(summary['p'], 1)
        self.assertEqual(summary['salt'], mask_hash(salt, show=2))
        self.assertEqual(summary['hash'], mask_hash(encoded.split('$')[-1]))
예제 #33
0
 def safe_summary(self, encoded):
     algorithm, salt, data = encoded.split('$', 2)
     assert algorithm == self.algorithm
     return {
         _('algorithm'): algorithm,
         _('salt'): salt,
         _('hash'): mask_hash(data, show=3),
     }
예제 #34
0
  def safe_summary(self, encoded):
    # the entire payload is base64-encoded
    assert encoded.startswith('SSHA')

    # strip off the hash label
    digest_salt_b64 = encoded[5:]

    # the password+salt buffer is also base64-encoded.  decode and split the
    # digest and salt
    digest_salt = base64.b64decode(digest_salt_b64)
    digest = digest_salt[:20]
    salt = digest_salt[20:]

    return OrderedDict([
      (_('algorithm'), 'SSHA'),
      (_('iterations'), 0),
      (_('salt'), mask_hash(str(salt))),
      (_('hash'), mask_hash(str(digest))),
    ])
예제 #35
0
    def safe_summary(self, encoded):
        """
        Returns a summary of safe values

        The result is a dictionary and will be used where the password field
        must be displayed to construct a safe representation of the password.
        """
        return SortedDict([
            (_('algorithm'), self.algorithm),
            (_('hash'), mask_hash(encoded, show=16)),
        ])
예제 #36
0
    def safe_summary(self, encoded):
        """
        Returns a summary of safe values

        The result is a dictionary and will be used where the password field
        must be displayed to construct a safe representation of the password.
        """
        return SortedDict([
            (_('algorithm'), self.algorithm),
            (_('hash'), mask_hash(encoded, show=16)),
        ])
예제 #37
0
 def get_context(self, name, value, attrs):
     context = super().get_context(name, value, attrs)
     summary = []
     if not value:
         summary.append({'label': gettext("No password set.")})
     else:
         summary.append({
             'label': gettext(_('hash')),
             'value': mask_hash(value)
         })
     context['summary'] = summary
     return context
예제 #38
0
    def safe_summary(self, encoded: str) -> dict:
        """
		Returns a summary of safe values.

		The result is a dictionary that will be used where the password field
		must be displayed to construct a safe representation of the password.

		:param encoded: The full encoded hash string.
		:return: The parameters.
		:rtype: dict
		:returns: All parameters exploded.
		"""
        decoded = self.decode(encoded)

        return {
            _('algorithm'): decoded['algorithm'],
            _('n'): decoded['n'],
            _('r'): decoded['r'],
            _('p'): decoded['p'],
            _('dklen'): decoded['dklen'],
            _('hash'): mask_hash(decoded['hash']),
            _('salt'): mask_hash(decoded['salt'])
        }
예제 #39
0
    def safe_summary(self, encoded):
        """Returns a summary of safe values.

        The result is an :py:class:``~collections.OrderedDict`` and will be
        used where the password field must be displayed to construct a safe
        representation of the password.

        >>> hasher = PlainPasswordHasher()
        >>> hasher.safe_summary(hasher.encode('secret', 'salt'))
        OrderedDict([('algorithm', 'plain'), ('hash', u'sec***')])

        """
        algorithm, salt, hash = encoded.split('$', 2)
        assert algorithm == self.algorithm
        return OrderedDict([
            ('algorithm', self.algorithm),
            ('hash', mask_hash(hash, show=3)),
        ])
예제 #40
0
 def render_field(self, request, obj, field):
     """Рендерит поле объекта модели."""
     if '.' in field:
         data = obj
         for part in field.split('.'):
             if data is None:
                 break
             data = getattr(data, part, None)
         field = part
     else:
         data = getattr(obj, field, None)
     if MASK_PASSWORD_FIELDS and field == 'password' and data:
         return mask_hash(data)
     if isinstance(data, FieldFile):
         if data.name:
             return data.url
         return None
     elif isinstance(data, Model):
         return [data.pk, force_text(data)]
     elif isinstance(data, Manager):
         return [(i.pk, force_text(i)) for i in data.all()]
     return data
예제 #41
0
 def safe_summary(self, encoded):
     return OrderedDict([
         ('algorithm', self.algorithm),
         ('hash', mask_hash(encoded, show=3)),
     ])
예제 #42
0
 def safe_summary(self, encoded):
     summary = self.summary(encoded)
     return {'name': summary['name'],
             'salt': mask_hash(summary['salt']),
             'code': mask_hash(summary['code'])}
예제 #43
0
 def safe_summary(self, encoded):
     algorithm, pghash = encoded.split("$", 1)
     assert algorithm == self.algorithm
     return SortedDict([(_("algorithm"), algorithm), (_("hash"), mask_hash(pghash))])
예제 #44
0
파일: hashers.py 프로젝트: RestAuth/server
 def safe_summary(self, encoded):  # pragma: no cover
     algorithm, salt, hash = encoded.split("$", 3)
     assert algorithm == self.algorithm
     return SortedDict([("algorithm", algorithm), ("salt", mask_hash(salt)), ("hash", mask_hash(hash))])
예제 #45
0
 def safe_summary(self, encoded):
     return SortedDict([(_("algorithm"), self.algorithm), (_("hash"), mask_hash(encoded, show=3))])
예제 #46
0
파일: models.py 프로젝트: yongshuo/mazeGame
 def password(self):
     return mask_hash(self.password_hash)
예제 #47
0
 def safe_summary(self, encoded):
     return SortedDict([
         (_('algorithm'), self.algorithm),
         (_('hash'), mask_hash(encoded, show=3)),
     ])
예제 #48
0
 def safe_summary(self, encoded):
     algorithm, salt, hash = encoded.split("$", 2)
     assert algorithm == self.algorithm
     return SortedDict(
         [(_("algorithm"), algorithm), (_("salt"), mask_hash(salt, show=2)), (_("hash"), mask_hash(hash))]
     )
예제 #49
0
 def get_FIELD_mask(self, field):
     value = getattr(self, field.attname)
     return mask_hash(value)