private void ButtonSignUp_Click(object sender, EventArgs e)
        {
            if (!(textBoxFirstNameSignUp.Text == "First Name") && !(textBoxLastNameSignUp.Text == "Last Name"))
            {
                if (textBoxPassSignUp.Text == textBoxConfirmPassSignUp.Text)
                {
                    //MessageBox.Show("Sign up pressed");
                    FacultyUserModel faculty = new FacultyUserModel();
                    faculty.AcademicId = textBoxAcademicIdSignUp.Text;
                    faculty.FirstName  = textBoxFirstNameSignUp.Text;
                    faculty.LastName   = textBoxLastNameSignUp.Text;
                    faculty.Email      = textBoxEmailSignup.Text;
                    faculty.Password   = textBoxPassSignUp.Text;
                    //faculty.CreatedAt =
                    //faculty.CreatedAt = DateTime.Now;

                    try
                    {
                        faculty.IsValid();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }

                    MessageBox.Show("Data accepted");

                    try
                    {
                        var controller = new UserController();
                        controller.Create(faculty);
                        buttonCancel.PerformClick();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show("Passwords do not match");
                }
            }
            else
            {
                MessageBox.Show("Please fill up all fields");
            }
        }
        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(textBoxFirstName.Text) && !string.IsNullOrWhiteSpace(textBoxLastName.Text) && !string.IsNullOrWhiteSpace(textBoxEmail.Text))
            {
                FacultyUserModel updatedModel = new FacultyUserModel();
                updatedModel.AcademicId = faculty.AcademicId;
                updatedModel.FirstName  = textBoxFirstName.Text.Trim();
                updatedModel.LastName   = textBoxLastName.Text.Trim();
                updatedModel.Email      = textBoxEmail.Text.ToLower().Trim();
                updatedModel.Id         = faculty.Id;
                updatedModel.Password   = faculty.Password;

                try
                {
                    updatedModel.IsValid();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                if (MessageBox.Show("Save changes?", "Confirmation", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    try
                    {
                        var controller = new UserController();
                        faculty = controller.Update(updatedModel);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            else
            {
                MessageBox.Show("Please fill up all fields");
            }
        }
예제 #3
0
        private void ButtonSignUp_Click(object sender, EventArgs e)
        {
            if (!(textBoxFirstNameSignUp.Text == "First Name") && !(textBoxLastNameSignUp.Text == "Last Name"))
            {
                if (textBoxPassSignUp.Text == textBoxConfirmPassSignUp.Text)
                {
                    LoadingForm loading = new LoadingForm();
                    loading.Show();
                    FacultyUserModel faculty = new FacultyUserModel();
                    faculty.AcademicId = textBoxAcademicIdSignUp.Text;
                    faculty.FirstName  = textBoxFirstNameSignUp.Text.Trim();
                    faculty.LastName   = textBoxLastNameSignUp.Text.Trim();
                    faculty.Email      = textBoxEmailSignup.Text.ToLower().Trim();
                    faculty.Password   = textBoxPassSignUp.Text;

                    try
                    {
                        faculty.IsValid();
                        loading.Step(20);
                        //hashing now
                        Argon2Hashing hashing = new Argon2Hashing();
                        faculty.salt     = Convert.ToBase64String(hashing.CreateSalt());
                        faculty.Password = Convert.ToBase64String(hashing.HashPassword(textBoxPassSignUp.Text, Convert.FromBase64String(faculty.salt)));
                        loading.Step(20);
                        //hashing done
                        //Console.WriteLine("Salt: " + faculty.salt);
                        //Console.WriteLine("Hashed password: "******"Verify hash: " + hashing.VerifyHash(textBoxPassSignUp.Text, Convert.FromBase64String(faculty.salt), Convert.FromBase64String(faculty.Password)));
                        loading.Step(20);
                        try
                        {
                            var controller = new UserController();
                            controller.Create(faculty);
                            loading.Step(20);
                            loading.Close();
                            MessageBox.Show("Account created. Please login with your email and password");
                            buttonCancel.PerformClick();
                        }
                        catch (SQLiteException ex)
                        {
                            loading.Close();
                            if (ex.ErrorCode == 19)
                            {
                                MessageBox.Show("An account is already registered with this email or ID");
                            }
                            else
                            {
                                MessageBox.Show(ex.Message + ex.ErrorCode);
                            }
                        }catch (Exception ex)
                        {
                            loading.Close();
                            MessageBox.Show(ex.Message);
                        }
                    }
                    catch (Exception ex)
                    {
                        loading.Close();
                        MessageBox.Show(ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show("Passwords do not match");
                }
            }
            else
            {
                MessageBox.Show("Please fill up all fields");
            }
        }
        private void buttonSave_Click(object sender, System.EventArgs e)
        {
            LoadingForm loadingForm = new LoadingForm();

            loadingForm.Show();
            //try
            {
                UserController controller = new UserController();
                Argon2Hashing  hashing    = new Argon2Hashing();
                //Console.WriteLine("getting pass with id: " + faculty.Id);
                //Console.WriteLine("Verification: " + hashing.VerifyHash(textBoxPassword.Text, Convert.FromBase64String(faculty.salt), Convert.FromBase64String(faculty.Password)));
                if (hashing.VerifyHash(textBoxPassword.Text, Convert.FromBase64String(faculty.salt), Convert.FromBase64String(faculty.Password)))
                {
                    loadingForm.Step(20);
                    if (textBoxNewPassword.Text == textBoxConfirmPassword.Text)
                    {
                        faculty.Password = textBoxNewPassword.Text;
                        //try
                        {
                            faculty.IsValid();
                            faculty.salt     = Convert.ToBase64String(hashing.CreateSalt());
                            faculty.Password = Convert.ToBase64String(hashing.HashPassword(faculty.Password, Convert.FromBase64String(faculty.salt)));
                            loadingForm.Step(20);
                            if (hashing.VerifyHash(textBoxNewPassword.Text, Convert.FromBase64String(faculty.salt), Convert.FromBase64String(faculty.Password)))
                            {
                                loadingForm.Step(20);
                                //try
                                {
                                    controller.UpdatePasswordByUser(faculty.Id, faculty.Password, faculty.salt);
                                    loadingForm.Step(60);
                                    loadingForm.Close();
                                    MessageBox.Show("Password successfully updated");
                                    this.Hide();
                                }
                                //catch(Exception ex)
                                //{
                                //    loadingForm.Close();
                                //    MessageBox.Show(ex.Message);
                                //}
                            }
                            else
                            {
                                loadingForm.Close();
                                MessageBox.Show("Hash verification failed");
                            }
                        }
                        //catch (Exception ex)
                        //{
                        //    loadingForm.Close();
                        //    MessageBox.Show(ex.Message+" here");
                        //}
                    }
                    else
                    {
                        loadingForm.Close();
                        MessageBox.Show("Passwords do not match. Please make sure you confirm your password correctly");
                    }
                }
                else
                {
                    loadingForm.Close();
                    MessageBox.Show("Wrong current password. Please try again");
                }
            }

            //catch (Exception ex)
            //{

            //    loadingForm.Close();
            //    MessageBox.Show(ex.Message);
            //}
        }