HTML Markup:
- <div id="Form2" runat="server">
- <h3 class="form-title">
- Login to your account</h3>
- <div class="alert alert-error hide">
- <button class="close" data-dismiss="alert">
- </button>
- <span>Enter any username and passowrd.</span>
- </div>
- <label>
- Username</label>
- <asp:TextBox ID="txtEmailAddress" autocomplete="off" placeholder="Username" runat="server"></asp:TextBox>
- <label>
- Password</label>
- <asp:TextBox ID="txtPasswords" autocomplete="off" placeholder="Username" runat="server" TextMode="Password"></asp:TextBox>
- <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:
- using System;
- using System.Data;
- using System.Configuration;
- using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Xml.Linq;
- using MySql.Data.MySqlClient;
- using System.Text;
- using System.Net;
- using System.IO;
-
- public class clsFunction
- {
- public clsFunction()
- {
-
-
-
- }
- public static string Encryptdata(string password)
- {
- string strmsg = string.Empty;
- byte[] encode = new byte[password.Length];
- encode = Encoding.UTF8.GetBytes(password);
- strmsg = Convert.ToBase64String(encode);
- return strmsg;
- }
- public static string Decryptdata(string encryptpwd)
- {
- string decryptpwd = string.Empty;
- UTF8Encoding encodepwd = new UTF8Encoding();
- Decoder Decode = encodepwd.GetDecoder();
- byte[] todecode_byte = Convert.FromBase64String(encryptpwd);
- 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);
- return decryptpwd;
- }
Step 2: Login Button Code
- protected void btnLogin_Click(object sender, EventArgs e)
- {
- string sign_in = "Select * from tbl_user where Login_id='" + txtEmailAddress.Text.Trim() + "' and Password='" + clsFunction.Encryptdata(txtPasswords.Text.Trim()) + "'";
- DataTable dt_SignUp = c1.filldt(sign_in);
- if (dt_SignUp.Rows.Count > 0)
- {
- Session["Admin_login"] = Convert.ToInt32(dt_SignUp.Rows[0]["User_id"].ToString());
- clsVariable.User_id = Convert.ToInt32(dt_SignUp.Rows[0]["User_id"].ToString());
- clsVariable.User_name = dt_SignUp.Rows[0]["User_name"].ToString();
- Response.Redirect("Dashboard.aspx");
- }
- }
Step 3: Insert into Database
- string str_ch = clsFunction.Encryptdata(txtPassword.Text);
- string str = "Insert into tbl_user (Password)values('" + str_ch + "');