Forgot Username Module

Asp.net has the ability to recover passwords based on username. Users typically log into my site once a year and many have forgotten their username. Is there anyway for a user to enter their email address to recover their forgotten username?

Examples would be awesome. Thanks.

usually when registering the email is required to be unique (the username as well). GEtting the username associated with an email is a trivial SQL matter


select username from users where email=@email

HOwever there isn’t any module doing that automatically unless you’re using the Asp.Net Membership provider

  <p class="instructions">If you forgot your password, you can use this page to have it sent to you by e-mail.</p>
  <asp:PasswordRecovery ID="prRecoverPassword" runat="server">
    <UserNameTemplate>
      <p>Step 1: Enter your username</p>
      <table>
        <tr>
          <td>Username:</td>
          <td><asp:TextBox ID="UserName" runat="server"></asp:TextBox></td>
          <td><asp:RequiredFieldValidator runat="server" ID="rfvUserNameRequired" ControlToValidate="UserName" Display="dynamic" SetFocusOnError="True"
              ErrorMessage="Username is required." ToolTip="User Name is required." ValidationGroup="prRecoverPassword">*</asp:RequiredFieldValidator>
          </td>
        </tr>
        <tr>
          <td colspan="3">
            <asp:Label runat="server" id="labFailureText" EnableViewState="False"></asp:Label>
            <asp:Button runat="server" ID="SubmitButton" CommandName="Submit" Text="Submit" ValidationGroup="prRecoverPassword" />
          </td>
        </tr>
      </table>
    </UserNameTemplate>
  
    <QuestionTemplate>
      <p>Step 2: Answer the following question</p>
      <table>
        <tr>
          <td>Username:</td>
          <td><asp:Literal runat="server" ID="UserName"></asp:Literal></td>
          <td></td>
        </tr>
        <tr>
          <td>Question:</td>
          <td><asp:Literal runat="server" ID="Question"></asp:Literal></td>
          <td></td>
        </tr>
        <tr>
          <td>Answer:</td>
          <td><asp:TextBox runat="server" ID="Answer"></asp:TextBox></td>
          <td>
            <asp:RequiredFieldValidator runat="server" ID="rfvAnswerRequired" Display="Dynamic" ControlToValidate="Answer" SetFocusOnError="True"
              ErrorMessage="Answer is required" ValidationGroup="prRecoverPassword"></asp:RequiredFieldValidator>
          </td>
        </tr>
        <tr>
          <td colspan="3">
            <asp:Label runat="server" ID="labFailureText" EnableViewState="False"></asp:Label>
            <asp:Button runat="server" ID="SubmitButton" CommandName="Submit" Text="Submit" ValidationGroup="prRecoverPassword" />
          </td>
        </tr>
      </table>
    </QuestionTemplate>
    <SuccessTemplate>
      <asp:Label runat="server" ID="lblSuccess" Text="Your password has been sent to you."></asp:Label>
    </SuccessTemplate>
    <MailDefinition 
      BodyFileName="~/TextFiles/PasswordRecoveryMail.txt" 
      From="admin@yourwebsitecom" 
      Subject="Your Recovered Password">
    </MailDefinition>
  
  </asp:PasswordRecovery>

Hi PInch, I am looking to recover the USERNAME not the password. Any ideas?

Sorry, I don’t know how. But you mean so they can enter their password and get their name? Seems as long as both are stored away there should be some way to do that.

I’m guessing that’s a rather rare scenario, may have to write some lines.

No, they enter their email address and the username is emailed to them.

Email addresses aren’t necessarily unique. I don’t know that it’s a good idea to go this route. If someone can’t remember their user name I’m not sure you can expect them to remember their email address. :stuck_out_tongue:

I know what you’re going through though. I had one lady that freaked out when I logged in on her computer because she didn’t know her user name and as long as it wasn’t changed she just had to remember the password. Strangely, her user name was her actual name. :lol:

You could try to require they use their real names but as you see that isn’t foolproof either.

Perhaps by policy but not by .NET Membership.

I was talking about a generic membership, truth be told I don’t know why people are using the asp.net membership…

I use it because it’s already done. I just need a basic log in with roles. :slight_smile: