當用戶登錄時,他提供了他的名字和原始密碼,該密碼被散列並與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
我怎麼能存儲原始用戶的密碼,並將其替換所需的功能呢?