当前位置: 首页>>代码示例>>Python>>正文


Python hashers.is_password_usable方法代码示例

本文整理汇总了Python中django.contrib.auth.hashers.is_password_usable方法的典型用法代码示例。如果您正苦于以下问题:Python hashers.is_password_usable方法的具体用法?Python hashers.is_password_usable怎么用?Python hashers.is_password_usable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.auth.hashers的用法示例。


在下文中一共展示了hashers.is_password_usable方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _finalize_without_domain

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import is_password_usable [as 别名]
def _finalize_without_domain(self):
        if not is_password_usable(self.action.user.password):
            AccountResetPasswordView.send_reset_token(self.action.user, self.request)
            return Response({
                'detail': 'Success! We sent you instructions on how to set your password.'
            })
        login_url = self.request.build_absolute_uri(reverse('v1:login'))
        return Response({
                'detail': f'Success! Please log in at {login_url}.'
            }) 
开发者ID:desec-io,项目名称:desec-stack,代码行数:12,代码来源:views.py

示例2: assertPassword

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import is_password_usable [as 别名]
def assertPassword(self, email, password):
        if password is None:
            self.assertFalse(is_password_usable(User.objects.get(email=email).password))
            return

        password = password.strip()
        self.assertTrue(User.objects.get(email=email).check_password(password),
                        'Expected user password to be "%s" (potentially trimmed), but check failed.' % password) 
开发者ID:desec-io,项目名称:desec-stack,代码行数:10,代码来源:test_user_management.py

示例3: clean

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import is_password_usable [as 别名]
def clean(self, *args, **kwargs):
        data = super(UserForm, self).clean(*args, **kwargs)

        if 'user_id' not in self.data:  # we're trying to create a new user

            if not data.get('raw_password'):
                self._errors['raw_password'] = self.error_class(['This field is required'])

            if not data.get('confirm_password'):
                self._errors['confirm_password'] = self.error_class(['This field is required'])

            if data.get('raw_password') != data.get('confirm_password'):
                self._errors['confirm_password'] = self.error_class(['The passwords do not match'])

            data['password'] = data.get('raw_password')
            if not is_password_usable(make_password(data['password'])):
                self._errors['raw_password'] = self.error_class(['Please enter a different password'])

            user_model = get_user_model()
            if data.get('email'):
                try:
                    user_model.objects.get(email__iexact=data['email'])
                    user_model.objects.get(username__iexact=data['email'][:30])
                    self._errors['email'] = self.error_class(['This email address is already in use'])
                except user_model.DoesNotExist:
                    pass

        else:
            if data.get('raw_new_password'):
                if data['raw_new_password'] != data.get('confirm_new_password'):
                    self._errors['confirm_new_password'] = self.error_class(['The passwords do not match'])

                data['new_password'] = data.get('raw_new_password')
                if not is_password_usable(make_password(data['new_password'])):
                    self._errors['raw_new_password'] = self.error_class(['Please enter a different password'])

        return data 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:39,代码来源:forms.py

示例4: set_password_updated_at

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import is_password_usable [as 别名]
def set_password_updated_at(apps, schema_editor):
    User = apps.get_model("accounts", "User")
    for u in User.objects.all():
        if is_password_usable(u.password):
            u.password_updated_at = u.date_joined
            u.save() 
开发者ID:zentralopensource,项目名称:zentral,代码行数:8,代码来源:0006_auto_20170927_1144.py

示例5: has_usable_password

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import is_password_usable [as 别名]
def has_usable_password(self):
        return is_password_usable(self.password) 
开发者ID:ehooo,项目名称:django_mqtt,代码行数:4,代码来源:models.py

示例6: test_user_already_logged_in

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import is_password_usable [as 别名]
def test_user_already_logged_in(self):
        USERNAME = PASSWORD = 'myuser'
        server_user = User.objects.create_user(USERNAME, 'my@user.com', PASSWORD)
        consumer = self._get_consumer()
        with UserLoginContext(self, server_user):
            # try logging in and auto-follow all 302s
            self.client.get(reverse('simple-sso-login'), follow=True)
            # check the user
            client_user = get_user(self.client)
            self.assertFalse(is_password_usable(client_user.password))
            self.assertTrue(is_password_usable(server_user.password))
            for key in ['username', 'email', 'first_name', 'last_name']:
                self.assertEqual(getattr(client_user, key), getattr(server_user, key)) 
开发者ID:mediafactory,项目名称:yats,代码行数:15,代码来源:tests.py

示例7: test_walkthrough

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import is_password_usable [as 别名]
def test_walkthrough(self):
        USERNAME = PASSWORD = 'myuser'
        server_user = User.objects.create_user(USERNAME, 'my@user.com', PASSWORD)
        consumer = self._get_consumer()
        # verify theres no tokens yet
        self.assertEqual(Token.objects.count(), 0)
        response = self.client.get(reverse('simple-sso-login'))
        # there should be a token now
        self.assertEqual(Token.objects.count(), 1)
        # this should be a HttpResponseRedirect
        self.assertEqual(response.status_code, HttpResponseRedirect.status_code)
        # check that it's the URL we expect
        url = urlparse(response['Location'])
        path = url.path
        self.assertEqual(path, reverse('simple-sso-authorize'))
        # follow that redirect
        response = self.client.get(response['Location'])
        # now we should have another redirect to the login
        self.assertEqual(response.status_code, HttpResponseRedirect.status_code, response.content)
        # check that the URL is correct
        url = urlparse(response['Location'])
        path = url.path
        self.assertEqual(path, reverse('login'))
        # follow that redirect
        login_url = response['Location']
        response = self.client.get(login_url)
        # now we should have a 200
        self.assertEqual(response.status_code, HttpResponse.status_code)
        # and log in using the username/password from above
        response = self.client.post(login_url, {'username': USERNAME, 'password': PASSWORD})
        # now we should have a redirect back to the authorize view
        self.assertEqual(response.status_code, HttpResponseRedirect.status_code)
        # check that it's the URL we expect
        url = urlparse(response['Location'])
        path = url.path
        self.assertEqual(path, reverse('simple-sso-authorize'))
        # follow that redirect
        response = self.client.get(response['Location'])
        # this should again be a redirect
        self.assertEqual(response.status_code, HttpResponseRedirect.status_code)
        # this time back to the client app, confirm that!
        url = urlparse(response['Location'])
        path = url.path
        self.assertEqual(path, reverse('simple-sso-authenticate'))
        # follow it again
        response = self.client.get(response['Location'])
        # again a redirect! This time to /
        url = urlparse(response['Location'])
        path = url.path
        self.assertEqual(path, reverse('root'))
        # if we follow to root now, we should be logged in
        response = self.client.get(response['Location'])
        client_user = get_user(self.client)
        self.assertFalse(is_password_usable(client_user.password))
        self.assertTrue(is_password_usable(server_user.password))
        for key in ['username', 'email', 'first_name', 'last_name']:
            self.assertEqual(getattr(client_user, key), getattr(server_user, key)) 
开发者ID:mediafactory,项目名称:yats,代码行数:59,代码来源:tests.py


注:本文中的django.contrib.auth.hashers.is_password_usable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。