简体   繁体   中英

Custom User Model extending AbstractUser, authenticate return None

I want create my custom user extending AbstractUser , but when i want authenticate my custom user return None.

When i create CustomUser() is stored in database but the passwowrd is not encrypted. Can i use authenticate function of banckend default? or i must create a custom backend for my custom user.

i added:

AUTH_USER_MODEL = 'mysite.customuser'

I think extending of AbstractUser, my class don't have same method or something is wrong

SOLVED!

The problem was not to extend AbstracUser, the problem was when i saved the user, CustomUser(username='myusername', password='mypassword'), the password is saved like plain text and de function authenticate() doesn't work with this.

It's necessary save user usinng UserCreationForm, or extending it, the most important is save() method because use set_password() method which set encrypted password so authenticate() method works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM