2017-08-31 76 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'])