2017-08-31 34 views
0

我有一個數據庫用戶名和密碼(純文本),現在我必須創建一個登錄應用程序,所以我需要一個最好的方式,我如何創建一個登錄可以使用Django註冊或任何登錄其他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  
+0

需要更多的細節,你的意思'沒有work' –

+0

如何https://docs.djangoproject.com/en/1.11/ref/contrib/auth/#django.contrib.auth.models。 User.set_password –

回答

0

如果您想創建註冊應用程序,則可以使用Google搜索教程。 Google中的第二個鏈接https://simpleisbetterthancomplex.com/tutorial/2017/02/18/how-to-create-user-sign-up-view.html

基於https://docs.djangoproject.com/en/1.11/topics/auth/default/ 如果您需要填寫您的用戶表。

from django.contrib.auth.models import User 
users_dict = { 
    'johndoe': {'email':'[email protected]', 'password': '12345678'} 
} 
for username, data in users_dict.items(): 
    user = User.objects.create_user(username, data['email'], data['password'])