Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am try to enable admins a way to change passwords for when a user forgets their answer to the security question. But I can not get it to work. Username is login name. Here is my code:


VB
Protected Sub btnResetPasswordClick(sender As Object, e As EventArgs)
       Dim userName As Label = Me.FormViewUserAccess.FindControl("UserNameLabel")
      
       Dim mp As MembershipProvider = Membership.Providers("AspNetAdminMembership")
       Dim user As MembershipUser = mp.GetUser(userName, False)
       Dim pass As String = user.ResetPassword
       Dim mm As New System.Net.Mail.MailMessage("mysite.com", user.Email)
       mm.Subject = "My Website"
       mm.Body = "Your password has been changed to: " & vbCrLf & pass & vbCrLf & _
           "Please login and change your password" & vbCrLf & _
            " SYSTEM GENERATED EMAIL - DO NOT RESPOND"

       Dim client As New SmtpClient
       Try
           client.Send(mm)
       Catch ex As Exception

       End Try
End Sub



Here is what I have in my webconfig:

XML
<membership>
    <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
        <add name="AspNetAdminMembership" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
    </providers>
</membership>


Can someone point out where I am going wrong, I am new to asp.net and I get the following error: The provider user key supplied is invalid. It must be of type System.Guid.
Parameter name: providerUserKey
Posted
Comments
manognya kota 27-Jan-12 0:50am    
Hi,

doubt here..User name is the login name of the the user who is requesting for a password reset?

1 solution

Hi,

Check if this works.

http://forums.asp.net/t/1077393.aspx/1[^]
 
Share this answer
 
Comments
Andy Morris 1-Feb-12 16:13pm    
I finally got it to work. I had a reference problem (mp.GetUser(userName, False) should have been mp.GetUser(userName.text, False) but the link you referenced helped.
Thanks
manognya kota 1-Feb-12 22:53pm    
oh yes..How did we miss that? username is a label and not the string:)Anyway Good luck!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900