Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The solution of check_password Verification failure in django2.2.6

Shulou Source: shulou.com Published: 2022-06-02 05:10:28 10月16日 Update

This article introduces the relevant knowledge of "the solution to the failure of check_password verification in django2.2.6". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Add custom authentication CustomBackend (mailbox, mobile phone number, etc.) to python3.6, django 2.2.6 AUTHENTICATION_BACKENDS

The password of a Super Admin created with python manage.py createsuperuser always fails to verify when logging in (False)

#.\ apps\ users\ backends\ other.py

#! / usr/bin/env python3#-*-coding: utf-8-*-"" @ author: yinzhuoqun@site: http://zhuoqun.info/@email: yin@zhuoqun.info@time: 18:06 on 2019-10-16 "from django.contrib.auth import get_user_modelfrom django.contrib.auth.backends import ModelBackendfrom django.db.models import Qfrom django.contrib.auth.hashers import check_passwordfrom apps.users.models import UserProfileUser = get_user_model () # user A unique value field other than the name can also be used to log in Setting should have corresponding configuration AUTHENTICATION_BACKENDSclass CustomBackend (ModelBackend): def authenticate (self, request, username=None, password=None, * * kwargs): try: # login user = UserProfile.objects.get (Q (username=username) | Q (email=username) | Q (phone=username)) # user_check_password = user.check_password (password) user_check_password = check_password (password) User.password) if user_check_password: return user except User.DoesNotExist: return None

Copy

# settings.py

AUTH_USER_MODEL = 'users.UserProfile' # users of the reloaded system Let UserProfile take effect # AUTH method (login of mailbox, mobile phone number, etc.), and verify that AUTHENTICATION_BACKENDS = ('apps.users.backends.other.CustomBackend', #' social_core.backends.weibo.WeiboOAuth3', # 'social_core.backends.qq.QQOAuth3', #' social_core.backends.weixin.WeixinOAuth3', # 'social_core.backends.github.GithubOAuth3', #' social_core.backends.gitlab.GitLabOAuth3') from top to bottom # 'django.contrib.auth.backends.ModelBackend',)

Copy

Delete the library to rebuild countless times can not, suddenly thought of using shell to reset the password once, sure enough, logged on.

(tracbug).\ tracbug > python manage.py shellPython 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32Type "help", "copyright" "credits" or "license" for more information. (InteractiveConsole) > > from django.contrib.auth import get_user_model > User = get_user_model () > user = User.objects.get (username= "yinzhuoqun") > > user > user.username'yinzhuoqun' > user.set_password ("xxxxxxxx") > user.save () "the solution to check_password Verification failure in django2.2.6" ends here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Login authentication mobile phone user mailbox method content password mobile phone number more user name knowledge no practical successful next number dilemma field actual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Tech Info Redmi vpn MariaDB