简体   繁体   中英

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:

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. Read more about it in User authentication in Django .

However, you can customize it or rewrite it completely (use your own logic). Read more about it in Customizing authentication in Django .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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