Roy*_*yal 3 django django-models django-forms django-admin django-views
views.py 保存密码:
elif 'reset_password' in request.POST:
if request.POST['reset_password'].strip():
saveuser = User.objects.get(id=user.id)
saveuser.set_password(request.POST['reset_password']);
saveuser.save()
userform = UserForm(instance=saveuser)
return redirect('incident.views.about_me')
Run Code Online (Sandbox Code Playgroud)
弹出框获取旧密码和新密码
<div id="overlay_form" style="display:none">
<form method="post" action=".">
{% csrf_token %}
<h2>Reset Password</h2><br />
<table>
<tr><td>Enter your old password</td><td>
<input type="text" name="old_password" id="old_password" maxlength="30" /></td></tr>
<tr><td>Enter your new password</td><td><input type="text" name="new_password" id="new_password" maxlength="30" /></td></tr>
<tr><td>Confirm your new password</td><td><input type="text" name="reset_password" id="reset_password" maxlength="30" /></td></tr>
</table>
<div style="width:180px;float:right;margin:20px 5px 0 10px">
{% include "buttons/save.html" %}
<button style="margin-right:10px;" type="button" id="close" name="cancel" class="forward backicon">
<img src="{{ STATIC_URL }}images/button-icon-ir-back.png" width="12" height="17" alt="" />
Cancel</button>
</div>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
我可以保存新密码,但我想知道以下内容
如何使用现有密码检查输入的旧密码是否正确。
如何验证新密码字段和确认密码字段。哪个验证更好执行。
需要一些帮助。
这是您检查旧密码的方式 - 在set_password,
user.check_password(request.POST['reset_password'])
Run Code Online (Sandbox Code Playgroud)
另外,通过以下方式检查密码确认。
elif 'reset_password' in request.POST:
old_password = request.POST['old_password'].strip()
reset_password = request.POST['reset_password'].strip()
new_password = request.POST['new_password'].strip()
if old_password && reset_password && reset_password == new_password:
saveuser = User.objects.get(id=user.id)
if user.check_password(old_password):
saveuser.set_password(request.POST['reset_password']);
saveuser.save()
userform = UserForm(instance=saveuser)
return redirect('incident.views.about_me')
Run Code Online (Sandbox Code Playgroud)
使用form.
| 归档时间: |
|
| 查看次数: |
7562 次 |
| 最近记录: |