DESIGN
AFTER CLICK A SAVE BUTTON
private void butSave_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(conn);
con.Open();
string un = txtUserName.Text.ToString().Trim();
string pw = txtPassword.Text.ToString().Trim();
string pass = "";
byte[] asciiBytes = Encoding.ASCII.GetBytes(pw);
for (int i = 0; i < pw.Length; i++)
{
int pw1 = asciiBytes[i] - 24;
string sssss = ((char)pw1).ToString();
pass = pass + sssss;
}
int op = 0;
if (radioEmployee.Checked == true)
{
op = 0;
}
else if(radioOwner.Checked == true)
{
op = 1;
}
string query = "insert into LOGIN(User_Name,Pass_Word,Owner_Permission) values('" + un + "','" + pass + "','" + op + "')";
SqlCommand cmd = new SqlCommand(query, con);
cmd.ExecuteNonQuery();
MessageBox.Show("Saved Successfully");
}
LOGIN FORM
LOGIN CLICK BUTTON (UserName and Password Checking from Database)
private void butLogin_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(conn);
con.Open();
string un = txtUsername.Text.ToString().Trim();
string pw = txtPassword.Text.ToString().Trim();
string find = "select * from IBS_LOGIN where User_Name = '" + un + "' and Pass_Word = '" + pass + "'";
SqlCommand findquery = new SqlCommand(find, con);
SqlDataReader dr = findquery.ExecuteReader();
if (dr.Read())
{
if (dr["Owner_Permission"].ToString() == "1")
{
GlobalDeclare.linknewaccount = 1;
}
else
{
GlobalDeclare.linknewaccount = 0;
}
if (dr["User_Name"].ToString() == un && dr["Pass_Word"].ToString() == pass)
{
RegistryKey rkey = Registry.CurrentUser.OpenSubKey(@"Control Panel\International", true);
rkey.SetValue("sShortDate", "dd/MM/yyyy");
IBSSTOCK ibs = new IBSSTOCK();
ibs.Show();
}
else
{
MessageBox.Show("Not Valid.User Name and Password Is Worng.");
dr.Close();
}
}
No comments:
Post a Comment