Python django.contrib.auth.hashers.is_password_usable() Examples
The following are 7
code examples of django.contrib.auth.hashers.is_password_usable().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.contrib.auth.hashers
, or try the search function
.
Example #1
Source File: views.py From desec-stack with MIT License | 5 votes |
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}.' })
Example #2
Source File: test_user_management.py From desec-stack with MIT License | 5 votes |
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)
Example #3
Source File: forms.py From urbanfootprint with GNU General Public License v3.0 | 5 votes |
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
Example #4
Source File: 0006_auto_20170927_1144.py From zentral with Apache License 2.0 | 5 votes |
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()
Example #5
Source File: models.py From django_mqtt with GNU General Public License v2.0 | 5 votes |
def has_usable_password(self): return is_password_usable(self.password)
Example #6
Source File: tests.py From yats with MIT License | 5 votes |
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))
Example #7
Source File: tests.py From yats with MIT License | 4 votes |
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))