naga jyothi

naga jyothi

  • NA
  • 62
  • 108.8k

how to encrypt the data to insert into sql database and also decrypt the data from the database

Jul 25 2012 2:48 AM
DataSet ds = new DataSet();
 
  string sql = "select Count,UserType,UserName,Password from Users where UserName = '" + txtUserName.Text + "'";
  SqlDataReader dr = conn.SqlReaderQuery(sql);
  try
  {
  if (!dr.Read() || dr["Password"].ToString() != txtPwd.Text)
  {
  MessageBox.Show("Enter Correct Username/Password");
  txtPwd.Text = "";
  txtUserName.Text = "";
  txtUserName.Focus();
  }
  else
  {
  int Count = Convert.ToInt16(dr["Count"].ToString());

  string usertype = "";
  usertype = dr["UserName"].ToString();
  if (usertype == txtUserName.Text)
  {
  if (Count < 10)
  {
  Count++;

  string ad = "";
  ad = dr["UserType"].ToString();
  if (ad == "Administrator")
  {

  frmMain fm = new frmMain();
  fm.Show();
  this.Hide();
  string Update = "update  Users set Count='" + Count + "'where UserName='" + txtUserName.Text + "'and Password='" + txtPwd.Text + "'";
  string HUpdate = "update  Users set Count='" + Count + "'where UserType='HumanResource'";
  dbConnection.ExecuteSQL(Update);
  dbConnection.ExecuteSQL(HUpdate);
  MessageBox.Show(Count.ToString());
  }
  else if (ad == "HumanResource")
  {


  frmHRMain hrm = new frmHRMain();
  hrm.Show();
  this.Hide();
  string Update = "update  Users set Count='" + Count + "'where UserName='" + txtUserName.Text + "'and Password='" + txtPwd.Text + "'";
  string HrUpdate = "update  Users set Count='" + Count + "'where UserType='Administrator'";
  dbConnection.ExecuteSQL(Update);
  dbConnection.ExecuteSQL(HrUpdate);
  MessageBox.Show(Count.ToString());
  }
 
 
  }

  else if (Count >= 10)
  {
  //  MessageBox.Show("Your Demo Version is Expired Please contact to Adminstrator");
  MessageBox.Show("Your Login Expired Please contact to Adminstrator", Count.ToString());
  // MessageBox.Show("Your Login Expired Please contact to Adminstrator", "Invalid Login", Count.ToString(), MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.LeftAlign, "http://csofttechnologies.in/Contact.html", "Please Buy a registre");
  }
  }
  }
  }
 
  catch (Exception ex)
  {
  MessageBox.Show(ex.Message);
  frmDbPath db = new frmDbPath();
  db.ShowDialog();
  }
  finally
  {
  //dr.Close();
  }
dr.Close();

  // my question is how to encrypt the data is insert into sql database and also decrypt the data  from the database


 

Answers (3)