Password: Encryption and Decryption of Password in ASP.NET C#

HTML Markup: 
  1. <div id="Form2" runat="server">  
  2.     <h3 class="form-title">  
  3. Login to your account</h3>  
  4.     <div class="alert alert-error hide">  
  5.         <button class="close" data-dismiss="alert">  
  6. </button>  
  7.         <span>Enter any username and passowrd.</span>  
  8.     </div>  
  9.     <label>  
  10. Username</label>  
  11.     <asp:TextBox ID="txtEmailAddress" autocomplete="off" placeholder="Username" runat="server"></asp:TextBox>  
  12.     <label>  
  13. Password</label>  
  14.     <asp:TextBox ID="txtPasswords" autocomplete="off" placeholder="Username" runat="server" TextMode="Password"></asp:TextBox>  
  15.     <asp:Button ID="btnLogin" class="btn green pull-right" runat="server" Text="Login" onclick="btnLogin_Click" />  
C#:  In Cs File Write This Code,
 
Step 1:  
  1. using System;  
  2. using System.Data;  
  3. using System.Configuration;  
  4. using System.Linq;  
  5. using System.Web;  
  6. using System.Web.Security;  
  7. using System.Web.UI;  
  8. using System.Web.UI.HtmlControls;  
  9. using System.Web.UI.WebControls;  
  10. using System.Web.UI.WebControls.WebParts;  
  11. using System.Xml.Linq;  
  12. using MySql.Data.MySqlClient;  
  13. using System.Text;  
  14. using System.Net;  
  15. using System.IO;  
  16.   
  17. public class clsFunction   
  18. {  
  19.     public clsFunction()  
  20.   {  
  21.         //  
  22.         // TODO: Add constructor logic here  
  23.         //  
  24.     }  
  25.     public static string Encryptdata(string password)  
  26.     {  
  27.         string strmsg = string.Empty;  
  28.         byte[] encode = new byte[password.Length];  
  29.         encode = Encoding.UTF8.GetBytes(password);  
  30.         strmsg = Convert.ToBase64String(encode);  
  31.         return strmsg;  
  32.     }  
  33.     public static string Decryptdata(string encryptpwd)  
  34.     {  
  35.         string decryptpwd = string.Empty;  
  36.         UTF8Encoding encodepwd = new UTF8Encoding();  
  37.         Decoder Decode = encodepwd.GetDecoder();  
  38.         byte[] todecode_byte = Convert.FromBase64String(encryptpwd);  
  39.         int charCount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);  
  40.         char[] decoded_char = new char[charCount];  
  41.         Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);  
  42.         decryptpwd = new String(decoded_char);  
  43.         return decryptpwd;  
  44.     }   
Step 2: Login Button Code 
  1. protected void btnLogin_Click(object sender, EventArgs e)   
  2. {  
  3.     string sign_in = "Select * from tbl_user where Login_id='" + txtEmailAddress.Text.Trim() + "' and Password='" + clsFunction.Encryptdata(txtPasswords.Text.Trim()) + "'";  
  4.     DataTable dt_SignUp = c1.filldt(sign_in);  
  5.     if (dt_SignUp.Rows.Count > 0)  
  6.     {  
  7.         Session["Admin_login"] = Convert.ToInt32(dt_SignUp.Rows[0]["User_id"].ToString());  
  8.         clsVariable.User_id = Convert.ToInt32(dt_SignUp.Rows[0]["User_id"].ToString());  
  9.         clsVariable.User_name = dt_SignUp.Rows[0]["User_name"].ToString();  
  10.         Response.Redirect("Dashboard.aspx");  
  11.     }  
  12.  
Step 3: Insert into Database  
  1. string str_ch = clsFunction.Encryptdata(txtPassword.Text);   
  2.  string str = "Insert into tbl_user (Password)values('" + str_ch + "');////Pass this string