예제 #1
0
        public async Task <bool> AddAccount(AccountDto dto, IHttpContextAccessor context)
        {
            if (_ragnarokConfigurations.UseMd5Pass)
            {
                dto.user_pass = Md5Converter.Hash(dto.user_pass);
            }
            string ipAddress = context.HttpContext.Connection.RemoteIpAddress.ToString();

            if (!string.IsNullOrEmpty(ipAddress))
            {
                string[] addresses = ipAddress.Split(',');
                if (addresses.Length != 0)
                {
                    dto.last_ip = addresses[0];
                }
                else
                {
                    dto.last_ip = ipAddress;
                }
            }
            var entity = _mapper.Map <AccountEntity>(dto);
            await _accountRepository.Add(entity);

            await _accountRepository.SaveChanges();

            return(entity.account_id > 0 ? true : false);
        }
예제 #2
0
        public bool ValidateLogin(LoginDto dto)
        {
            if (_ragnarokConfigurations.UseMd5Pass)
            {
                dto.user_pass = Md5Converter.Hash(dto.user_pass);
            }
            var user = _repo.GetAll().Where(s => s.userid == dto.userid && s.user_pass == dto.user_pass).ToList();

            if (user.Count == 1)
            {
                return(true);
            }
            return(false);
        }
        private static void buttonConfirm_Click(object sender, EventArgs e)
        {
            string username        = textBoxUsername.Text;
            string password        = textBoxPassword.Text;
            string confirmPassword = textBoxConfirmPassword.Text;

            if (username == "" || username.Replace(" ", "") == "")
            {
                MessageBox.Show("Username cannot be empty.");
                return;
            }
            if (!Program.getDatabaseUtils().isUsernameUnique(username))
            {
                MessageBox.Show("This Username has been taken. Please try another.");
                return;
            }
            if (password == "" || password.Replace(" ", "") == "")
            {
                MessageBox.Show("Password cannot be empty.");
                return;
            }
            if (confirmPassword == "" || confirmPassword.Replace(" ", "") == "")
            {
                MessageBox.Show("Confirm password cannot be empty.");
                return;
            }
            if (password != confirmPassword)
            {
                MessageBox.Show("Password is not match.");
                return;
            }
            password = Md5Converter.encrypt(password);
            bool createAccount = Program.getDatabaseUtils().addNewUser(username, password, EnumUser.Student, StudentRegistrationForm.getStudentName(), StudentRegistrationForm.getGender(), StudentRegistrationForm.getDateOfBirth(),
                                                                       StudentRegistrationForm.getEmail(), StudentRegistrationForm.getContactNumber(), StudentRegistrationForm.getAddress());

            if (!createAccount)
            {
                MessageBox.Show("An error occurred! Failed to create account.");
            }
            else
            {
                hideAllComponents();
                StudentInformationForm.showAllComponents();
                StudentInformationForm.updateStudentInformation(username);
            }
        }
        private static void buttonSave_Click(object sender, EventArgs e)
        {
            Student student = (Student)User.getCurrentUser();

            if (student == null)
            {
                MessageBox.Show("An error occurred while doing this process.");
                return;
            }
            if (textBoxStudentName.Text == "" || textBoxStudentName.Text.Replace(" ", "") == "")
            {
                err.SetError(textBoxStudentName, "Student name cannot be empty.");
                return;
            }
            bool changePassword = false;

            if ((textBoxOldPassword.Text != "" || textBoxOldPassword.Text.Replace(" ", "") != "") &&
                (textBoxNewPassword.Text != "" || textBoxNewPassword.Text.Replace(" ", "") != "") &&
                (textBoxConfirmPassword.Text != "" || textBoxConfirmPassword.Text.Replace(" ", "") != ""))
            {
                if (Md5Converter.encrypt(textBoxOldPassword.Text) != student.Password)
                {
                    err.SetError(textBoxOldPassword, "Wrong password.");
                    MessageBox.Show("Old password is wrong!");
                    return;
                }
                else
                {
                    err.SetError(textBoxOldPassword, "");
                }

                if (textBoxNewPassword.Text != textBoxConfirmPassword.Text)
                {
                    err.SetError(textBoxConfirmPassword, "New Password is not match.");
                    MessageBox.Show("New Password is not match.!");
                    return;
                }
                else
                {
                    err.SetError(textBoxConfirmPassword, "");
                }
                changePassword = true;
            }
            else if (textBoxOldPassword.Text != "" || textBoxOldPassword.Text.Replace(" ", "") != "" ||
                     (textBoxNewPassword.Text != "" || textBoxNewPassword.Text.Replace(" ", "") != "") ||
                     textBoxConfirmPassword.Text != "" || textBoxConfirmPassword.Text.Replace(" ", "") != "")
            {
                MessageBox.Show("You must fill in the passwords to change the new password!");
                return;
            }
            student.Password    = Md5Converter.encrypt(textBoxNewPassword.Text);
            student.Name        = textBoxStudentName.Text;
            student.Gender      = radioButtonMale.Checked ? EnumGender.Male : EnumGender.Female;
            student.DateOfBirth = dateTimePicker1.Value.Date;
            student.Email       = textBoxEmail.Text;
            student.Contact     = textBoxContact.Text;
            student.Address     = textBoxAddress.Text;
            Program.getDatabaseUtils().updateStudentInformation(student, changePassword);
            hideSomeComponents();
            StudentProfileForm.showAllComponents();
            StudentProfileForm.updateStudentInformation();
            Program.getStudentForm().initProfileName();
        }
예제 #5
0
        public void login()
        {
            string username = textBoxUsername.Text;
            string password = textBoxPassword.Text;

            if (password == "")
            {
                MessageBox.Show("Username cannot be empty.");
                return;
            }
            if (password == "")
            {
                MessageBox.Show("Password cannot be empty.");
                return;
            }
            password = Md5Converter.encrypt(password);
            User user = Program.getDatabaseUtils().verifyUser(username, password);

            if (user == null)
            {
                this.textBoxPassword.Text = "";
                return;
            }
            User.setCurrentUser(user);
            clearTextboxes();
            switch (user.Type)
            {
            case EnumUser.Staff:
                Program.getLoginForm().Hide();
                Program.initStaffForm();
                Program.getStaffForm().initProfileName();
                Program.getStaffForm().setCurrentSelectedLabel(1);
                StudentRegistrationForm.showAllComponents();
                Program.getStaffForm().ShowDialog();
                Program.getLoginForm().Close();
                break;

            case EnumUser.Tutor:
                Program.getLoginForm().Hide();
                Program.initTutorForm();
                Program.getTutorForm().initProfileName();
                Program.getTutorForm().setCurrentSelectedLabel(1);
                TutorClassScheduleForm.showAllComponents();
                TutorClassScheduleForm.updateTutorInformation();
                Program.getTutorForm().ShowDialog();
                Program.getLoginForm().Close();
                break;

            case EnumUser.Student:
                Program.getLoginForm().Hide();
                Program.initStudentForm();
                Program.getStudentForm().initProfileName();
                Program.getStudentForm().setCurrentSelectedLabel(1);
                StudentProfileForm.showAllComponents();
                StudentProfileForm.updateStudentInformation();
                Program.getStudentForm().ShowDialog();
                Program.getLoginForm().Close();
                break;

            default:
                MessageBox.Show("An error occurred while logging in.");
                break;
            }
        }