private void CreatePassword(IS2G10_DBSSSDataSet.USERPROFILERow userProfile)
        {
            _password = null;

            var createPasswordWindow = new CreatePassword();

            if (createPasswordWindow.ShowDialog() == true)
            {
                _password = createPasswordWindow.Password; //values preserved after close
            }

            if (_password != null && !_password.Equals(""))
            {
                string hash;
                string salt;
                _passwordBuilder.CreateHash(_password, out hash, out salt);
                userProfile.resetPassword = false;
                userProfile.password_hash = hash;
                userProfile.password_salt = salt;
                _userProfileTableAdapter.Update(userProfile);

                _dialogService.CallMessageModal(this, "", SSS_Library.Properties.Resources.Login_CheckPassword_Password_Created_Successfully);
            }

            if (_password != null && _password.Equals("") || _password == null)
            {
                _dialogService.CallMessageModal(this, "", SSS_Library.Properties.Resources.Login_CheckPassword_Please_Enter_a_Password_);
            }
        }
        private bool CheckPassword(IS2G10_DBSSSDataSet.USERPROFILERow userProfile, string sPass)
        {
            var check = _passwordBuilder.CheckPassword(sPass, userProfile.password_hash, userProfile.password_salt);

            //check if password is right
            if (!check)
            {
                _dialogService.CallMessageModal(this, "", SSS_Library.Properties.Resources.IncorrectLoginDetailsMessage);
                PasswordTextBox.Clear();
                UsernameTextBox.Clear();
                UsernameTextBox.Focus();
            }
            return(check);
        }
Example #3
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            var sInput    = medUsername.Text;
            var sPassword = medPassword.Text;

            if (sPassword.Equals("HereBeDragons") && (sInput.Equals("Admin") || sInput.Equals("admin") || sInput.Equals("Administrator") || sInput.Equals("administrator")))
            {
                Form adminShow = new Administrator.Administrator();
                adminShow.Owner = this;
                adminShow.Show();
                this.Hide();
            }
            else if (!SSS_Library.DataServices.StringHandler.CheckIfStringANumber(sInput) || !sPassword.Equals("HereBeDragons") && (sInput.Equals("Admin") || sInput.Equals("admin") || sInput.Equals("Administrator") || sInput.Equals("administrator")))
            {
                MessageBox.Show(String.Format("{0}", Resources.IncorrectLoginDetailsMessage));
                medPassword.Clear();
                medUsername.Clear();
                medUsername.Focus();
            }
            else
            {
                _userId = Convert.ToInt32(sInput);

                IS2G10_DBSSSDataSet.USERPROFILERow userProfile = userprofileTableAdapter1.GetData().FindByuser_id(_userId);

                if (userProfile == null)
                {
                    MessageBox.Show(String.Format("{0}", Resources.IncorrectLoginDetailsMessage));
                    medPassword.Clear();
                    medUsername.Clear();
                    medUsername.Focus();
                }
                else
                {
                    if (userProfile.resetPassword)
                    {
                        CreatePassword(userProfile);
                    }
                    else
                    {
                        var doILogin = CheckPassword(userProfile, sPassword);

                        if (doILogin)
                        {
                            //coordinator role = 2
                            if (userProfile.user_roles_id == 2)
                            {
                                Form coordinatorShow = new Coordinator.Coordinator(_userId);
                                coordinatorShow.Owner = this;
                                coordinatorShow.Show();
                                this.Hide();
                            }
                            //student role = 4
                            else if (userProfile.user_roles_id == 4)
                            {
                                Form studentShow = new SSS_Windows_Forms.Student(_userId);
                                studentShow.Owner = this;
                                studentShow.Show();
                                this.Hide();
                            }
                            //tutor role = 3
                            else if (userProfile.user_roles_id == 3)
                            {
                                Form tutorShow = new Tutor.Tutor(_userId);
                                tutorShow.Owner = this;
                                tutorShow.Show();
                                this.Hide();
                            }
                        }
                    }
                }
            }
        }