[英]django-registration seems to be shortening hashed password when using subclassed RegistrationView
[英]django, entering a hashed password in registration and storing it as such
我正在openopenx(在django上工作)上,我需要創建一個api來注冊來自特定站點的用戶,我得到的是散列密碼,而不是普通密碼,因此我需要將其保存。
這里的問題是,opendx的注冊功能會散列傳遞給它的密碼。
所以在django中有一種方法可以存儲密碼/注冊用戶而不散列密碼。
我應該直接使用更新用戶的憑證嗎
raw()
任何幫助,將不勝感激,謝謝。
我建議重寫user_model中的方法set_password
。
class MyUser(AbstractBaseUser):
# if you need to hash passwords for some users.
is_password_hashed = models.BooleanField(default=True)
...
def set_password(self, raw_password):
if self.is_password_hashed:
super(MyUser, self).set_password(raw_password)
else:
self.password = raw_password
如果只想存儲非哈希密碼:
class MyUser(AbstractBaseUser):
...
def set_password(self, raw_password):
self.password = raw_password
甚至覆蓋默認的用戶模型set_password
方法。
就像這樣簡單:
from django.contrib.auth.models import User
User.objects.filter(username="myuser").update(password=hashed_password)
(記住密碼以哈希值的形式存儲在數據庫中)
Open edX manage_user
管理命令最近已更新,以在創建新用戶時支持此用例。
例:
./manage.py lms --settings=devstack manage_user jane jane@example.com --initial-password-hash 'pbkdf2_sha256$20000$mRxYkenyBiH6$yIk8aZYmWisW2voX5qP+cAr+i7R/IrZoohGsRK2fy4E='
但是,該命令需要Open edX的最新版本,並且如果用戶帳戶已存在,則該命令將無效。
或者,您可以使用OAuth2在外部應用程序和Open edX之間設置SSO,在這種情況下,根本不需要Open edX存儲任何密碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.