[英]Django login with plain password
我有一個使用用戶名和密碼(純文本)的數據庫,現在我必須創建一個登錄應用程序,因此我需要一種最好的方式來創建登錄名,我可以使用django注冊或其他任何django默認登錄應用程序來創建,使我的工作變得容易我嘗試過的是:
我創建了一個重復的表,並嘗試使用此代碼對其進行加密,但是它不起作用
import crypt
# To encrypt the password. This creates a password hash with a random salt.
password_hash = crypt.crypt(password)
# To check the password.
valid_password = crypt.crypt(cleartext, password_hash) == password_hash
如果要創建注冊應用,可以使用Google搜索教程。 Google中的第二個鏈接https://simpleisbetterthancomplex.com/tutorial/2017/02/18/how-to-create-user-sign-up-view.html
基於https://docs.djangoproject.com/zh-CN/1.11/topics/auth/default/如果需要填寫用戶表。
from django.contrib.auth.models import User
users_dict = {
'johndoe': {'email':'johndoe@doe.com', 'password': '12345678'}
}
for username, data in users_dict.items():
user = User.objects.create_user(username, data['email'], data['password'])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.