def safe_summary(self, encoded): algorithm, salt, hsh = encoded.split('$') return OrderedDict([ (_('algorithm'), algorithm), (_('salt'), mask_hash(salt, show=2)), (_('hash'), mask_hash(hsh)), ])
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)), ])
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), }
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)), ])
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)), ])
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)), ])
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)), ])
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)), ])
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)), ])
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), }
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)), ])
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)), ])
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)), ])
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)), ])
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)), ])
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)), ])
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)), ])
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)), ])
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)), ])
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)), ])
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)), ])
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)), ])
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)
def safe_summary(self, encoded): algorithm, pghash = encoded.split('$', 1) assert algorithm == self.algorithm return OrderedDict([ (_('algorithm'), algorithm), (_('hash'), mask_hash(pghash)), ])
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)
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})
def safe_summary(self, encoded): assert encoded.startswith('sha256$$') hash_ = encoded[8:] return OrderedDict([ (_('algorithm'), self.algorithm), (_('hash'), mask_hash(hash_)), ])
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]))
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), }
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))), ])
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)), ])
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
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']) }
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)), ])
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
def safe_summary(self, encoded): return OrderedDict([ ('algorithm', self.algorithm), ('hash', mask_hash(encoded, show=3)), ])
def safe_summary(self, encoded): summary = self.summary(encoded) return {'name': summary['name'], 'salt': mask_hash(summary['salt']), 'code': mask_hash(summary['code'])}
def safe_summary(self, encoded): algorithm, pghash = encoded.split("$", 1) assert algorithm == self.algorithm return SortedDict([(_("algorithm"), algorithm), (_("hash"), mask_hash(pghash))])
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))])
def safe_summary(self, encoded): return SortedDict([(_("algorithm"), self.algorithm), (_("hash"), mask_hash(encoded, show=3))])
def password(self): return mask_hash(self.password_hash)
def safe_summary(self, encoded): return SortedDict([ (_('algorithm'), self.algorithm), (_('hash'), mask_hash(encoded, show=3)), ])
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))] )
def get_FIELD_mask(self, field): value = getattr(self, field.attname) return mask_hash(value)