In this Post Decrypt Password for User Authentication in Asp.Net
Important Namespaces Used ---------------------------- using System.Data; using System.Data.SqlClient; using System.Text; ---------------------------- Variable Used -------------- static String decryptedpwd; -------------- Login Button Click Event ------------------------ String mycon = "Data Source=HP-PC\\SQLEXPRESS;Initial Catalog=UserLoginData;Integrated Security=True"; SqlConnection scon = new SqlConnection(mycon); String myquery = "select * from userlogin where username='" + TextBox1.Text + "'"; SqlCommand cmd = new SqlCommand(); cmd.CommandText = myquery; cmd.Connection = scon; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; DataSet ds = new DataSet(); da.Fill(ds); String uname; String pass; if (ds.Tables[0].Rows.Count > 0) { uname = ds.Tables[0].Rows[0]["username"].ToString(); pass = ds.Tables[0].Rows[0]["password"].ToString(); scon.Close(); decryptpwd(pass); if (uname == TextBox1.Text && decryptedpwd == TextBox2.Text) { Session["username"] = uname; Response.Redirect("Success.aspx"); } else { Label3.Text = "Invalid Login Details. Try to enter Username/password Carefully"; } } else { Label3.Text = "Invalid Login Details. Try to enter Username/password Carefully"; } -------------------- User Defined Method -------------------- private void decryptpwd(String encrytpwd) { string decryptpwd = string.Empty; UTF8Encoding encodepwd = new UTF8Encoding(); Decoder Decode = encodepwd.GetDecoder(); byte[] todecode_byte = Convert.FromBase64String(encrytpwd); int charCount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); decryptpwd = new String(decoded_char); decryptedpwd = decryptpwd; } ---------------- Success.aspx Page Coding ----------------------- Page Load Coding =========== Label2.Text = "Hello " + Session["username"] + " , Welcome to Our Website"; ------------ Logout button click event ------------------------- Session.Abandon(); Label2.Text = "You have successfully Logout"; Button1.Visible = false; -----------------