简体   繁体   English

如何手动验证用户

[英]How to manually authenticate user

I want to authenticate user manually how can I keep user signed in, in all applications of project?我想手动验证用户如何在项目的所有应用程序中保持用户登录? Here's my login view function:这是我的登录视图 function:

def sign(request):
    context = {}
    if request.method == 'POST':
        form = SigninForm(data = request.POST)
        if form.is_valid:
            username = request.POST['username']
            password = hashlib.sha256(request.POST['password'].encode('utf-8')).hexdigest()
            users = customer.objects.all()          
            for user in users:
                if username == user.username:
                    if password == user.password:
                        context['tmp'] = "OK"

Django has a built-in authentication system. Django 具有内置的身份验证系统。 Read more about it in User authentication in Django .在 Django 中的用户身份验证中了解更多信息。

However, you can customize it or rewrite it completely (use your own logic).但是,您可以自定义它或完全重写它(使用您自己的逻辑)。 Read more about it in Customizing authentication in Django . 在 Django 中的自定义身份验证中了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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