【发布时间】:2020-10-23 05:12:25
【问题描述】:
当我注册一个新用户时,他的密码在数据库中使用 sha1 方法加密。 当我想搜索用户是否已经在我的登录页面的数据库中注册时,我必须检查电子邮件地址是否存在以及发送的密码是否正确。 这是我的代码: *views.py :"
#Login
@api_view(['POST', ])
def log_in(request):
if request.method == 'POST':
data = {}
email = request.POST.get('email')
password = request.POST.get('password')
password = hashlib.sha1(password.encode('utf-8'))
account = memberArea.objects.filter(email = email, password = password)
if account.exists():
for account in account:
data['succes'] = "Successfully connected"
data['id'] = account.id
data['email'] = account.email
else :
data['error'] = "email and password doesn't match !"
return Response(data)
在这里,我尝试对用户发送的密码进行加密,然后在数据库中搜索此加密密码。 测试后不行。 提前感谢您对我的帮助。
【问题讨论】:
-
请勿在数据库中存储加密密码!请阅读一些关于如何正确处理具有唯一盐和不可逆哈希的密码的文章。任何不足都会让您在数据泄露中不恰当地容易让您的用户密码被盗。
标签: python django api django-rest-framework django-views