Password Reset only by Username [closed]

家住魔仙堡 提交于 2019-12-11 02:57:58

问题


I Implimented django password reset using email but currently want to restrict to only username so that user can change password only by using username. tried django built-in and plugin but unable to set to only username . Any suggestions would be appreciated


回答1:


Write your own reset password code. Pretty much the only code you need to write is the first step that gets the user, generates one-only link for resetting password and sends email.

Django does that with PasswordResetForm. Source code is here (lines 242 - 306). Copy/paste this code to your forms.py (including required imports) and modify it to accept username instead of email.

In your code you then validate your PasswordResetForm and call save() to generate one-only link and send mail.

form = YourPasswordResetForm(request.POST)
if form.is_valid():
    form.save()

Remember to always return success message, even if user doesn't exist and email wasn't sent, because otherwise you'll be giving out information about registered usernames.



来源:https://stackoverflow.com/questions/48243168/password-reset-only-by-username

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!