Saturday, May 2, 2009

Show Password in textbox in normal mode

Hi all,

If you want the user to change his passowrd then you has to show him his last password
that is in Normal mode.
Ex : if the password is "Testing" then if you show it directly in textbox where textbox mode is
Password will be shown as "******".
So now if you want to show it as "Testing".then below is solution for it:

Place the text box on the .aspx part

In the code behind call function on page_load

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoginInfo();
txtpass.Attributes.Add("value", viewstate["pwd"].ToString());
}
}

void LoginInfo()
{
Try

SqlCommand cmd = new SqlCommand("select PassHint from tbllogin where UserID=@aid ", new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString.ToString()));
cmd.CommandType = CommandType.Text;
cmd.Connection.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
if (dr.HasRows)
{
viewstate["pwd"] = dr["UserPass"].ToString();
}
}


dr_.Close();
cmd.Connection.Close();
cmd.Dispose();
catch (Exception ex)
{
//Response.Write(ex.ToString());
}
}

And you are done.

No comments:

Post a Comment