PasswordRecovery Component Samples

The PasswordRecovery control provides a multi-step password recovery flow: enter a username, answer a security question, and receive a success confirmation. In Web Forms this was <asp:PasswordRecovery>.


Default PasswordRecovery

The default layout provides a username step, a security question step, and a success step. Handle OnVerifyingUser to validate the username and set the security question via the SetQuestion method. Handle OnVerifyingAnswer to verify the answer.

Forgot Your Password?
Enter your User Name to receive your password.

Code:

<PasswordRecovery ID="PasswordRecovery1"
    OnVerifyingUser="HandleVerifyingUser"
    OnVerifyingAnswer="HandleVerifyingAnswer"
    OnSendingMail="HandleSendingMail" />

@code {
    void HandleVerifyingUser(LoginCancelEventArgs e)
    {
        // Look up the user. If valid, set the security question:
        var recovery = (PasswordRecovery)e.Sender;
        recovery.SetQuestion("What is your favorite color?");
        // Set e.Cancel = true to reject the username.
    }

    void HandleVerifyingAnswer(LoginCancelEventArgs e)
    {
        // Validate the answer against your data store.
        // Set e.Cancel = true to reject the answer.
    }

    void HandleSendingMail(MailMessageEventArgs e)
    {
        // Send the password reset email here.
    }
}

Custom Text Properties

Customize labels, titles, and messages for each step using the text properties.

Password Reset
Please enter your email address below.

Code:

<PasswordRecovery ID="PasswordRecovery2"
    UserNameTitleText="Password Reset"
    UserNameInstructionText="Please enter your email address below."
    UserNameLabelText="Email:"
    SubmitButtonText="Next"
    QuestionTitleText="Security Verification"
    QuestionInstructionText="Please answer your security question."
    SuccessText="A password reset link has been sent to your email."
    OnVerifyingUser="HandleVerifyingUser"
    OnVerifyingAnswer="HandleVerifyingAnswer" />

With Help Link

Use HelpPageText and HelpPageUrl to add a help link below the form.

Forgot Your Password?
Enter your User Name to receive your password.
Need more help?

Code:

<PasswordRecovery ID="PasswordRecovery3"
    HelpPageText="Need more help?"
    HelpPageUrl="/help/password-reset" />