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


Python hashers.check_password方法代码示例

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


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

示例1: form_valid

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import check_password [as 别名]
def form_valid(self, form):
        user_email = form.cleaned_data['email'].lower().strip()
        password = form.cleaned_data['password']
        user = authenticate(email=user_email, password=password)
        if user and user.is_active:
            login(self.request, user)
            return redirect(self.get_success_url())
        else:
            try:
                user = User.objects.get(email__iexact=user_email)
                if not check_password(password, user.password):
                    form._errors['password'] = ErrorList([u'That is not the correct Password.'])
            except User.DoesNotExist:
                form._errors['email'] = ErrorList([u'This email is not registered with us.'])
            context = self.get_context_data(form=form)
            return self.render_to_response(context) 
开发者ID:pixlie,项目名称:oxidizr,代码行数:18,代码来源:views.py

示例2: authenticate

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import check_password [as 别名]
def authenticate(self, request, username=None, password=None):
        login_valid = (settings.ADMIN_LOGIN == username)
        if settings.ADMIN_PASSWORD.startswith("pbkdf2_sha256"):
            pwd_valid = check_password(password, settings.ADMIN_PASSWORD)
        else:
            pwd_valid = password == settings.ADMIN_PASSWORD
        if login_valid and pwd_valid:
            try:
                user = User.objects.get(username=username)
            except User.DoesNotExist:
                # Create a new user. There's no need to set a password
                # because only the password from settings.py is checked.
                user = User(username=username)
                user.is_staff = True
                user.is_superuser = True
                user.save()
            return user
        return None 
开发者ID:palfrey,项目名称:wharf,代码行数:20,代码来源:auth.py

示例3: test_put

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import check_password [as 别名]
def test_put(self):
        old_password = '0ld_passworD'
        new_password = 'n3w_Password'
        user = UserFactory.create(password=old_password)

        token = default_token_generator.make_token(user)
        uid = urlsafe_base64_encode(force_bytes(user.pk))

        request = self.create_request(
            'put',
            data={'new_password': new_password, 'new_password2': new_password},
            auth=False,
        )
        view = self.view_class.as_view()
        response = view(request, uidb64=uid, token=token)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Get the updated user from the db
        user = User.objects.get(pk=user.pk)
        self.assertTrue(user.check_password(new_password)) 
开发者ID:incuna,项目名称:django-user-management,代码行数:22,代码来源:test_views.py

示例4: test_password_mismatch

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import check_password [as 别名]
def test_password_mismatch(self):
        old_password = '0ld_passworD'
        new_password = 'n3w_Password'
        invalid_password = 'different_new_password'
        user = UserFactory.create(password=old_password)

        token = default_token_generator.make_token(user)
        uid = urlsafe_base64_encode(force_bytes(user.pk))

        request = self.create_request(
            'put',
            data={
                'new_password': new_password,
                'new_password2': invalid_password,
            },
            auth=False,
        )
        view = self.view_class.as_view()
        response = view(request, uidb64=uid, token=token)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

        # Get the updated user from the db
        user = User.objects.get(pk=user.pk)
        self.assertTrue(user.check_password(old_password)) 
开发者ID:incuna,项目名称:django-user-management,代码行数:26,代码来源:test_views.py

示例5: test_update

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import check_password [as 别名]
def test_update(self):
        old_password = '0ld_passworD'
        new_password = 'n3w_Password'

        user = UserFactory.create(password=old_password)

        request = self.create_request(
            'put',
            user=user,
            data={
                'old_password': old_password,
                'new_password': new_password,
                'new_password2': new_password,
            })
        view = self.view_class.as_view()
        response = view(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        user = User.objects.get(pk=user.pk)
        self.assertTrue(user.check_password(new_password)) 
开发者ID:incuna,项目名称:django-user-management,代码行数:22,代码来源:test_views.py

示例6: test_update_wrong_old_password

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import check_password [as 别名]
def test_update_wrong_old_password(self):
        old_password = '0ld_passworD'
        new_password = 'n3w_Password'

        user = UserFactory.create(password=old_password)

        request = self.create_request(
            'put',
            user=user,
            data={
                'old_password': 'invalid_password',
                'new_password': new_password,
                'new_password2': new_password,
            })
        view = self.view_class.as_view()
        response = view(request)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

        user = User.objects.get(pk=user.pk)
        self.assertTrue(user.check_password(old_password)) 
开发者ID:incuna,项目名称:django-user-management,代码行数:22,代码来源:test_views.py

示例7: test_update_mismatched_passwords

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import check_password [as 别名]
def test_update_mismatched_passwords(self):
        old_password = '0ld_passworD'
        new_password = 'n3w_Password'
        invalid_password = 'different_new_password'

        user = UserFactory.create(password=old_password)

        request = self.create_request(
            'put',
            user=user,
            data={
                'old_password': old_password,
                'new_password': new_password,
                'new_password2': invalid_password,
            })
        view = self.view_class.as_view()
        response = view(request)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

        user = User.objects.get(pk=user.pk)
        self.assertTrue(user.check_password(old_password)) 
开发者ID:incuna,项目名称:django-user-management,代码行数:23,代码来源:test_views.py

示例8: fuzz_verifier_django

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import check_password [as 别名]
def fuzz_verifier_django(self):
        try:
            self._require_django_support()
        except SkipTest:
            return None
        from django.contrib.auth.hashers import check_password

        def verify_django(secret, hash):
            """django/check_password"""
            if self.handler.name == "django_bcrypt" and hash.startswith("bcrypt$$2y$"):
                hash = hash.replace("$$2y$", "$$2a$")
            if self.django_has_encoding_glitch and isinstance(secret, bytes):
                # e.g. unsalted_md5 on 1.5 and higher try to combine
                # salt + password before encoding to bytes, leading to ascii error.
                # this works around that issue.
                secret = secret.decode("utf-8")
            return check_password(secret, hash)
        return verify_django 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:20,代码来源:test_handlers_django.py

示例9: user_login

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import check_password [as 别名]
def user_login(request, email, password, connection=None):
    models = request.app.models
    user = await models.user.get_user_by_email(email, connection=connection)
    if user:
        if not user.is_active:
            raise web.HTTPForbidden(reason="User disabled")
        elif check_password(password, user.password):
            await models.user_action_log_entry.create_login(
                request, user_id=user.pk, connection=connection)
            token = request.app.context.jwt.generate(uid=user.id)
            return web.json_response(
                {
                    'uid': user.id,
                    'profile': await user.get_profile(connection=connection),
                    'token': token,
                }, headers={'Authorization': 'Bearer %s' % token},
            )
    raise web.HTTPUnauthorized(reason="Login incorrect") 
开发者ID:dvhb,项目名称:dvhb-hybrid,代码行数:20,代码来源:jwt.py

示例10: post

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import check_password [as 别名]
def post(self, request, format=None):
        data = request.data
        username = data.get('username')
        password = data.get('password')
        try:
            user = User.objects.get(username__exact=username)
        except User.DoesNotExist:
            user = None
        if user:
            if check_password(password, user.password):
                serializer = UserSerializer(user)
                new_data = serializer.data
                # 记忆已登录用户,作为用户是否拥有某项权限的认证
                # self.request.session['user_username'] = user.username
                token = Token.objects.get(user_id=user.id)
                q = Auth(configs.get('qiniu').get('AK'), configs.get('qiniu').get('SK'))
                base_url = configs.get('qiniu').get('domain') + '/'
                user_image_url = q.private_download_url(base_url + new_data.get('user_image_url'), expires=86400)
                timeArray = time.strptime(str(user.last_login), "%Y-%m-%d %H:%M:%S")
                new_obj = {
                    'id': user.id,
                    # 'password': user.password,
                    'username': new_data.get('username'),
                    'token': token.key,
                    'user_image_url': user_image_url,
                    'last_login': time.mktime(timeArray),
                }
                # print(time.mktime(timeArray))
                user.last_login = time.strftime("%Y-%m-%d %H:%M:%S")
                user.save(update_fields=['last_login'])
                return Response({"stateCode": 200, "msg": new_obj}, status=HTTP_200_OK)
            else:
                return Response({"stateCode": 202, "msg": "密码不正确"}, 202)  # 密码不正确
        else:
            return Response({"stateCode": 201, "msg": "用户不存在"}, 201)  # 用户不存在


# 生成商品图片上传的token 
开发者ID:michwh,项目名称:onehome-server,代码行数:40,代码来源:views.py

示例11: assertToken

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import check_password [as 别名]
def assertToken(self, plain, user=None):
        user = user or self.owner
        self.assertTrue(any(check_password(plain, hashed, preferred='pbkdf2_sha256_iter1')
                            for hashed in Token.objects.filter(user=user).values_list('key', flat=True)))
        self.assertEqual(len(Token.make_hash(plain).split('$')), 4) 
开发者ID:desec-io,项目名称:desec-stack,代码行数:7,代码来源:base.py

示例12: check_password

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import check_password [as 别名]
def check_password(self, raw_secret):
        """
        Return a boolean of whether the raw_password was correct. Handles
        hashing formats behind the scenes.
        """
        def setter(raw_secret):
            self.set_password(raw_secret)
            # Password hash upgrades shouldn't be considered password changes.
            self._secret = None
            self.save(update_fields=["secret"])
        return check_password(raw_secret, self.secret, setter) 
开发者ID:SubstraFoundation,项目名称:substra-backend,代码行数:13,代码来源:models.py

示例13: form_valid

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import check_password [as 别名]
def form_valid(self, form):
        user = self.request.user
        if not check_password(self.request.POST['oldpassword'], user.password):
            return JsonResponse({
                'error': True,
                'response': {'oldpassword': 'Invalid old password'}
            })
        if self.request.POST['newpassword'] != self.request.POST['retypepassword']:
            return JsonResponse({
                'error': True,
                'response': {'newpassword': 'New password and Confirm Passwords did not match'}
            })
        user.set_password(self.request.POST['newpassword'])
        user.save()
        return JsonResponse({'error': False, 'message': 'Password changed successfully'}) 
开发者ID:MicroPyramid,项目名称:django-simple-forum,代码行数:17,代码来源:views.py

示例14: test_successful_password_change

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import check_password [as 别名]
def test_successful_password_change(self):
        """Verify change success when entering password properly."""
        response = self._force_login_and_change_password({
            "oldpassword": self.password,
            "password1": self.new_password,
            "password2": self.new_password,
        })
        # User should be redirected if there are no form errors.
        self.assertRedirects(
            response=response, expected_url=reverse("account_change_password")
        )
        # Verify that user's new password was set correctly.
        # Re-retrieve user so that we can access new password.
        user = get_user_model().objects.get(email=self.user.email)
        assert hashers.check_password(self.new_password, user.password) 
开发者ID:pydata,项目名称:conf_site,代码行数:17,代码来源:test_password_change.py

示例15: authenticate

# 需要导入模块: from django.contrib.auth import hashers [as 别名]
# 或者: from django.contrib.auth.hashers import check_password [as 别名]
def authenticate(self, username=None, password=None):
        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            return None

        if check_password(password, user.password):
            return user

        # try running password through same scrypt params as front end.
        encoded_password = scrypt.hash(str(password), str(username), 16384, 8, 1).encode('hex')
        if check_password(encoded_password, user.password):
            return user
        return None 
开发者ID:priestc,项目名称:MultiExplorer,代码行数:16,代码来源:custom_auth_backend.py


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