User login logic

About registration of this issue, the login screen is also a form form, the user enters a user name and password, click the login button to submit the form form, we get the data entered by the user through the function we set, and then take the user's user name to the database match, If a match can not explain the value of the user name does not exist, we will inform the user at the front page, if the value of the match then there is a user name, we can further verify the password, if the password is correct then jump to page content page, if the password is wrong in the front page to the user.

def login(request):
    if request.method == "POST" and request.POST:
        name = request.POST.get("name")
        password = request.POST.get("password")
        user = User_one.objects.filter(userName=name)
        if user:
            if user[0].password == getPassword(password):
                return HttpResponseRedirect("/student/page_student_list/1/")
            else:
                key = "密码错误"
        else:
            key = "用户名不存在"
    return render(request,"login.html", locals())

Here Insert Picture DescriptionThe following is an encryption function that is used to encrypt passwords

import hashlib      #导入hashlib包
def getPassword(password):
    md5 = hashlib.md5()
    md5.update(password.encode())
    result = md5.hexdigest()
    return result

Of course, we would also like to follow-up on the inside to join cookie, here temporarily not joined

Published 21 original articles · won praise 9 · views 9572

Guess you like

Origin blog.csdn.net/Zhang_Chao_1998/article/details/86099727