我有一个登录和身份验证功能,它从表单中获取输入,验证来自数据库的数据,如果正确则返回 right.html,否则返回 wrong.html。密码存储在galaxy_user数据库中,uname的输出为:
u'sachitad'
passw 的输出是:
u'f8566297ee28e8a3096497070b37b91d24c24243'
def login(request):
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
u = ''.join(username)
p = hashlib.sha1(password).hexdigest()
a = GalaxyUser.objects.values_list('username', 'password')
uname = a[0][0]
passw = a[0][1]
user = authenticate(uname=u, passw=p)
if user is not None:
return render_to_response('right.html', context_instance=RequestContext(request))
else:
return render_to_response('wrong.html', context_instance=RequestContext(request))
else:
return render_to_response('login.html', context_instance=RequestContext(request))
编辑: GalaxyUser 表:
id | create_time | update_time | email | password | external | deleted | purged | username | form_values_id | disk_usage |
+----+---------------------+---------------------+-------------------------------+------------------------------------------+----------+---------+--------+----------+----------------+------------+
| 1 | 2013-01-11 15:00:30 | 2013-01-11 15:00:30 | user1@gmail.com | f8566297ee28e8a3096497070b37b91d24c24243 | 0 | 0 | 0 | sachitad | NULL | NULL |
| 2 | 2013-01-11 15:01:01 | 2013-01-11 15:01:01 | user2@zurelsoft.com | f8566297ee28e8a3096497070b37b91d24c24243 | 0 | 0 | 0 | saugat | NULL | NULL |
+----+---------------------+---------------------+-------------------------------+------------------------------------------+----------+---------+--------+-
我想使用电子邮件和密码进行身份验证。