Esempio n. 1
0
        public static void UpdateAdminPass(string password)
        {
            try
            {
                //PASS IN THE USER NAME AND THE NEW PASSWORD
                UserResetPassword.ResetUserPassword(AdminLog.Admin);
                SqlConnection con = new DBConnection().getConnection();
                con.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("@ID", UserResetPassword.Resetuserid);

                cmd.Parameters.AddWithValue("@Password", PasswordEncryptor.Encrypt(password));
                cmd.CommandText = "UPDATE Admin SET Password =@Password WHERE ID= @ID ";
                cmd.ExecuteNonQuery();
                con.Close();
                dataAccess.Description = Admin + " updated password";
                dataAccess.Activities();
                AdminPass = PasswordEncryptor.Encrypt(password);
            }
            catch (Exception Ex)
            {
                throw new Exception(Ex.Message + "\nUpdate Not Successful");
            }
        }
Esempio n. 2
0
        public static void DeleteAdmin(TextBox username)
        {
            //PASS IN THE USER NAME AND THE NEW PASSWORD
            SqlConnection con = new DBConnection().getConnection();

            try
            {
                if (string.IsNullOrEmpty(username.Text))
                {
                    throw new Exception("Enter Username to Delete");
                }
                CheckPrvilege();
                UserResetPassword.DeleteSecurityQuestion(username.Text);

                con.Open();
                SqlCommand cmCommand = new SqlCommand();
                cmCommand.Connection = con;
                cmCommand.Parameters.Clear();
                cmCommand.Parameters.AddWithValue("@UserName", username.Text);
                cmCommand.CommandText = "DELETE Admin WHERE UserName =@UserName";
                cmCommand.ExecuteNonQuery();
                con.Close();
                dataAccess.Description = "Deleted an Admin";
                dataAccess.Activities();
                MessageBox.Show("User Deleted", "Cash Desk", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            catch (Exception Ex)
            {
                con.Close();
                throw new Exception(Ex.Message + "\nDelete Not Successful");
            }
        }
Esempio n. 3
0
        /// <summary>
        /// /update the Admins
        /// </summary>
        /// <param name="pass"></param>
        /// <param name="passNew"></param>
        /// <param name="user"></param>
        /// <param name="newuser"></param>
        public static void UpdateAdminUsername(string user, string newuser)
        {
            SqlConnection con = new DBConnection().getConnection();

            con.Open();
            try
            {
                //check if user  already exist
                if (user != AdminLog.Admin)
                {
                    throw new Exception("User is not currently logged in\nLogin user and try again");
                }
                else
                {
                    CheckUserName(newuser);
                    UserResetPassword.ResetUserPassword(user);
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = con;
                    cmd.Parameters.Clear();
                    cmd.Parameters.AddWithValue("@UserName", newuser);
                    cmd.Parameters.AddWithValue("@Password", AdminLog.AdminPass);
                    cmd.Parameters.AddWithValue("@ID", UserResetPassword.Resetuserid);
                    cmd.CommandText = "UPDATE Admin SET UserName =@UserName WHERE ID=@ID";
                    cmd.ExecuteNonQuery();
                }
                con.Close();
                dataAccess.Description = Admin + " Updated username to " + newuser;
                dataAccess.Activities();
                Admin = newuser;
            }
            catch (Exception Ex)
            {
                throw new Exception(Ex.Message + "\nUpdate Not Successful");
            }
        }
Esempio n. 4
0
 private void btnReset_Click(object sender, EventArgs e)
 {
     try
     {
         if (string.IsNullOrEmpty(txtusername.Text))
         {
             throw new Exception("Enter New username");
         }
         if (string.IsNullOrEmpty(txtpass.Text))
         {
             throw new Exception("Enter new Password");
         }
         if (string.IsNullOrEmpty(txtConpass.Text))
         {
             throw new Exception("confirm password");
         }
         if (txtpass.Text != txtConpass.Text)
         {
             throw new Exception("Provided password mismatch");
         }
         else
         {
             UserResetPassword.UpdateAdminUsername(txtusername.Text, txtConpass.Text);
             MessageBox.Show("Password reset successful", "Password Reset", MessageBoxButtons.OK, MessageBoxIcon.Information);
             var login = new LoginForm();
             this.Hide();
             login.Show();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Password Reset", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Esempio n. 5
0
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            //frmMain frm = new frmMain();
            //this.Hide();
            //frm.ShowDialog();

            if (cmbUsername.Text == "" || txtPassword.Text == "")
            {
                MessageBox.Show("Invalid username or password!", "Falcon", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            using (SqlConnection conn = new SqlConnection(ClassDBUtils.DBConnString))
            {
                try
                {
                    conn.Open();
                    string usr = ""; string ps = ""; Boolean temppass = false;

                    SqlCommand    cmd = new SqlCommand("select [login], pass, temppass from users where [login] = '" + cmbUsername.Text + "'", conn);
                    SqlDataReader rd  = cmd.ExecuteReader();

                    while (rd.Read())
                    {
                        usr      = rd[0].ToString();
                        ps       = rd[1].ToString();
                        temppass = Convert.ToBoolean(rd[2].ToString());
                    }
                    rd.Close();

                    ClassGenLib.username = cmbUsername.Text;

                    if (ps == txtPassword.Text)
                    //if(ClassGenLib.HashPass(txtPassword.Text, 2020) == ps)
                    {
                        if (temppass == true) //new user or password has been reset therefore go to password dialog
                        {
                            UserResetPassword rest = new UserResetPassword(cmbUsername.Text);
                            rest.ShowDialog();
                        }
                        else
                        {
                            frmMain frm = new frmMain();
                            this.Hide();
                            frm.ShowDialog();
                            this.Close();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Invalid username or password!", "Falcon", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error attempting to access database! " + ex.Message, "Falcon", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Esempio n. 6
0
 public SecurityQuestions()
 {
     InitializeComponent();
     UserResetPassword.ShowSecurityQuestions();
     txQuest1.Text      = UserResetPassword.Question1;
     txtQuest2.Text     = UserResetPassword.Question2;
     this.ActiveControl = txtAnswer1;
 }
Esempio n. 7
0
        private void btnResetPass_Click(object sender, EventArgs e)
        {
            ForgotPassword forgetpass = new ForgotPassword();

            UserResetPassword.CreateSecurityTable("create");
            this.Hide();
            forgetpass.Show();
        }
Esempio n. 8
0
 private void btnNext_Click(object sender, EventArgs e)
 {
     try
     {
         if (string.IsNullOrEmpty(txtUsername.Text))
         {
             throw new Exception("Enter Username");
         }
         UserResetPassword.ResetUserPassword(txtUsername.Text);
         var securityquestions = new SecurityQuestions();
         this.Hide();
         securityquestions.Show();
     }catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Search Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Esempio n. 9
0
 private void btnSubmit_Click(object sender, EventArgs e)
 {
     try
     {
         if (string.IsNullOrEmpty(txQuest1.Text))
         {
             throw new Exception("Question 1 is empty");
         }
         if (string.IsNullOrEmpty(txtAnswer1.Text))
         {
             throw new Exception("Answer for question 1 is empty");
         }
         if (string.IsNullOrEmpty(txtQuest2.Text))
         {
             throw new Exception("Question 2 is empty");
         }
         if (string.IsNullOrEmpty(txtAnswer2.Text))
         {
             throw new Exception("Answer for question 2 is empty");
         }
         UserResetPassword.CreateSecurityTable();
         var Questionchecked = UserResetPassword.CheckSecurityQuestions();
         if (Questionchecked == 0)
         {
             //inset these questions
             UserResetPassword.SetSecurityQuestions(txQuest1.Text, txtAnswer1.Text, txtQuest2.Text, txtAnswer2.Text);
             MessageBox.Show("Question Set Successfully", "Security Questions", MessageBoxButtons.OK, MessageBoxIcon.Information);
             Clear();
         }
         else
         {
             //update the questions
             UserResetPassword.UpdateSecurityQuestions(txQuest1.Text, txtAnswer1.Text, txtQuest2.Text, txtAnswer2.Text);
             MessageBox.Show("Question Updated Successfully", "Security Questions", MessageBoxButtons.OK, MessageBoxIcon.Information);
             Clear();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Set Question Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }