當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。