---
title: "Retriving User Password by Using Stored Procedure in ASP.NET"  
description: "In this demonstration I will tell you how to retrieve user password by using Stored Procedure in ASP.NET. To perform this task I had created a UserLog"  
author: "Anonymous User"  
published: 2011-02-15  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/118/retriving-user-password-by-using-stored-procedure-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# Retriving User Password by Using Stored Procedure in ASP.NET

In this demonstration I will tell you how to [retrieve user](https://answers.mindstick.com/qa/30717/how-to-retrieve-user-name-in-case-of-window-authentication) [password](https://www.mindstick.com/blog/243/how-to-create-password-protected-report) by using [Stored Procedure](https://www.mindstick.com/articles/803/using-stored-procedure-in-asp-dot-net) in ASP.NET. To perform this task I had created a UserLogin [table in Sql](https://www.mindstick.com/forum/205/find-the-all-column-with-schema-for-any-table-in-sql-server) Server and enter some values like following example demonstrate…\

```
create table UserLogin (       userName varchar(20) not null,       userPassword varchar(20) not null,       primary key(userName , userPassword) )  --Enter some values in UserLogin tables -- insert into UserLogin values('aaaa','aaaa@123') insert into UserLogin values('bbbb','bbbb@123') insert into UserLogin values('cccc','cccc@123') insert into UserLogin values('dddd','dddd@123')
```

\

##### Create a parametrized procedure which return user password on the

##### basis of user name.

--Create an parametrize procedure to retrive user password from table based on username--

```
create procedure retriveUserPassword @userName varchar(20) as begin       select userPassword from UserLogin where userName=@userName end
```

Then create a [function in c#](https://answers.mindstick.com/qa/82408/what-is-function-in-c-sharp) which display user Password in form [alert box](https://www.mindstick.com/articles/12940/how-to-create-message-alert-box-using-jquery).

```
//For retriving password from ql server using procedure you have to use      //Two namespace named System.Data and System.Data.SqlClient.     //At the click event of button write down following line of code.      public void getUserPassword(string userName)     {         SqlConnection con = new SqlConnection();    //Create an SqlConnection object.         //Pass the connection string to the SqlConnection object         con.ConnectionString = "............";         con.Open();  //Open the connection         string procedureText = "retriveUserPassword";         SqlCommand cmd = new SqlCommand(procedureText, con); //Create an SqlCommand object.         cmd.CommandType = CommandType.StoredProcedure; //Change the behaviour of command text to stored procedure.         cmd.Parameters.Add(new SqlParameter("@userName",userName));  //Pass value to the parameter that you have created in procedure.         SqlDataReader dr = cmd.ExecuteReader();         if (dr.Read())         {             Response.Write("<script>alert('Password is  :" + dr[0].ToString() + "')</script>");         }         else         {             Response.Write("<script>alert('User Name does not exist')</script>");         }         con.Close();     }
```

Then finally call this method at the [click event](https://www.mindstick.com/forum/424/how-to-call-form_paint-event-on-button-click-event) of RecoverPassword button and you get password in form alert() message box.

---

Original Source: https://www.mindstick.com/blog/118/retriving-user-password-by-using-stored-procedure-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
