问题
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