private void btnSignup_Click(object sender, EventArgs e) { //Here the new user is automatically stored in the database for furthur logins. connection.Open(); OleDbDataAdapter da = new OleDbDataAdapter("select * from userDetail", connection); DataSet ds = new DataSet(); da.Fill(ds); int count = ds.Tables[0].Rows.Count + 1; OleDbCommand cmd = new OleDbCommand(); cmd.Connection = connection; if (txtSignPassword.Text == txtSignReEnter.Text) { cmd.CommandText = "insert into userDetail (userID,userName,userPassword,userPhone,userFlag,pID) values('" + count + "','" + txtSignUser.Text + "','" + txtSignPassword.Text + "','" + txtSignPhone.Text + "','true','2')"; cmd.ExecuteNonQuery(); MessageBox.Show("Sign up.Successfull"); // After successfully logging in the Home page must be loaded. homePage hp = new homePage(); hp.ShowDialog(); } connection.Close(); }
private void btnLogin_Click(object sender, EventArgs e) { connection.Open(); OleDbDataAdapter da = new OleDbDataAdapter("select * from userDetail", connection); DataSet ds = new DataSet(); da.Fill(ds); //When the User is in login mode the labels and textboxes of normal Login are visible and when not the recovery user name and phone no. are visible. // The basic login is turned on. if (lblUserName.Visible == true && lblPassword.Visible == true && lblPhoneNo.Visible == true) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (txtUserName.Text == ds.Tables[0].Rows[i][1].ToString() && txtPassword.Text == ds.Tables[0].Rows[i][2].ToString() && txtPhoneNo.Text == ds.Tables[0].Rows[i][3].ToString()) { flag = true; //here the flag determines that the user has logged in successfully OleDbCommand cmd = new OleDbCommand(); cmd.Connection = connection; cmd.CommandText = "update userDetail set userFlag = 'true' where userID = '" + ds.Tables[0].Rows[i][0].ToString() + "'"; cmd.ExecuteNonQuery(); // after loggin in the user in the database must be logged in so the userFlag is set to true for the logged person. } } } // if the recovery mode of login is turned on. if (txtRecoverUser.Visible == true && txtPhoneNo.Visible == true) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (txtRecoverUser.Text == ds.Tables[0].Rows[i][1].ToString() && txtPhoneNo.Text == ds.Tables[0].Rows[i][3].ToString()) { flag = true; OleDbCommand cmd = new OleDbCommand(); cmd.Connection = connection; cmd.CommandText = "update userDetail set userFlag = 'true' where userID = '" + ds.Tables[0].Rows[i][0].ToString() + "'"; cmd.ExecuteNonQuery(); // Same as normal login but for the recovered user. } } } // If the user is successfully logged in. if (flag == true) { MessageBox.Show("Login.Successfull"); // After successfully logging in the Home page must be loaded. homePage hp = new homePage(); hp.ShowDialog(); } else { MessageBox.Show("Invalid.User"); //Invalid user condition. } flag = false; connection.Close(); }