How to retrieve logged in user password using ASP.Net - Asp.Net Tutorials

 

Introduction

In this article you will get to know how to retrieve logged in user password using ASP.Net.

History

In the Previous articles i explained what is namespace for arraylistGet Selected RadioButton Value of RadioButtonList using C# and ASP.Nethow to create serial no. column in gridview using asp.net, Add check boxes column in DataGridView for deleting records from database, what is query string and how to use it in asp.net and many more about ASP.Net.

If you’re using the Membership API in asp.net and need to retrieve a user’s password, you can do so by doing this:

Step 1.

Add Namespace

using System.Web.Security;

Step 2.

MembershipUser currentUser = Membership.GetUser(); 
string password = currentUser.GetPassword("Security Answer");

It requires you to pass in the user’s security answer as an added check.

Step 3.

To support this feature, you’ll need to have password retrieval enabled in the web.config. You can do this in the <membership> node under <system.web>. It’ll look something like below :

    <membership defaultProvider="Sqlprovider">
            <providers>
                <clear/>
                <add connectionStringName="database_con" applicationName="MySqlConnection"  minRequiredPasswordLength="4"
             minRequiredNonalphanumericCharacters="0" enablePasswordRetrieval="true" enablePasswordReset="true"
             requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Clear" name="Sqlprovider" 
             type="System.Web.Security.SqlMembershipProvider"/>
            </providers>
        </membership>

Hope this Helps.

Note : Hashed passwords cannot be retrieved. The hash is one way while having the password format set to encrypted enables retrieval of passwords. I’ve updated the web.config File to ensure that passwords can be retrieved.

Give your Valuable Comments.
comments powered by Disqus
 
Follow me on twitter
About Me
Harpreet Singh
I began programming with C++ when i was 17. Then at the middle of my study .NET came. Then I began to read C# and VB.NET. By the time i learnt SQL and ASP.NET, and developed some websites such as news portals that are active now. Currently i am running my own Software company.
More Articles