当用户登录时,他提供了他的名字和原始密码,该密码被散列并与db的值进行比较。如何在django中重复使用原始用户的密码?
def login(request):
username = request.POST['username']
password = request.POST['password']
user = auth.authenticate(username=username, password=password)
if user is not None and user.is_active:
# user is active
auth.login(request, user)
# relink to right page
return HttpResponseRedirect("/account/loggedin/")
else:
# error page
return HttpResponseRedirect("/account/invalid/")
或者我可以只使用:
@login_required
def index(request):
if request.user.is_authenticated():
return render_to_response('polls/index.html', {'sessionDic' : request.session})
else:
#some stuff
的问题是:一旦用户登录,下面的请求包括仅进行检查和用户的Cookie也没有必要再次把他的证件。
但是,我需要查看具有原始用户的密码在每个方法登录到Linux用户和执行一些Linux程序作为该用户。对于〔实施例的su
程序是用来切换ritgh Linux用户:
def ssh_command (user, password, command):
child = pexpect.spawn('su -l %s -c \'%s\'' % (user, command))
i = child.expect([pexpect.TIMEOUT, pexpect.EOF, 'Password: '])
if i == 0: # Timeout
print 'ERROR!'
print 'su can\'t be executed:'
print child.before, child.after
return None
if i == 1: # EOF
print 'ERROR'
print 'EOF error'
print child.before, child.after
return None
child.sendline(password)
return child
def main():
user = 'test'
password = 'test'
child = ssh_command (user, password, 'curl habrahabr.ru | wc -c')
child.expect(pexpect.EOF)
print child.before
print child.after
print child.match
我怎么能存储原始用户的密码,并将其替换所需的功能呢?