Beispiel #1
0
 public Admin(DeanForm deanform, Dean dean)
 {
     this.dean       = dean;
     this.ID         = dean.ID;
     this.login      = dean.Login;
     this.password   = dean.Password;
     this.university = dean.University;
     this.faculty    = dean.Faculty;
     this.deanForm   = deanform;
 }
Beispiel #2
0
        private void SignInDeanButton_Click(object sender, EventArgs e)
        {
            Connection     connect = Connection.GetInstance();
            DataTable      table   = new DataTable();
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand     command = new SqlCommand();
            SqlDataReader  reader;
            string         login    = "";
            string         hash     = "";
            string         salt     = "";
            string         sqlQuery = "select login, password, salt from Dean where login = @log;";

            connect.OpenConnection();
            command.CommandText = sqlQuery;
            command.Connection  = connect.GetConnection();
            command.Parameters.Add("@log", SqlDbType.VarChar).Value = SignInlogindeantextBox.Text;
            reader = command.ExecuteReader();
            adapter.SelectCommand = command;
            while (reader.Read())
            {
                login = Convert.ToString(reader["login"]);
                hash  = Convert.ToString(reader["password"]);
                salt  = Convert.ToString(reader["salt"]);
            }
            reader.Close();
            if (login == SignInlogindeantextBox.Text && Hashing.Verify(salt, hash, SignInPasswordDeantextBox.Text))
            {
                Dean     dean     = new Dean(this);
                DeanForm deanForm = new DeanForm();
                Admin    admin    = new Admin(deanForm, dean);
                deanForm.SetAdmin(admin);
                deanForm.Show();
                this.Hide();
                connect.CloseConnection();
            }

            else
            {
                if (SignInlogindeantextBox.Text.Trim().Equals(""))
                {
                    MessageBox.Show("Enter your login", "Email field is empty", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if (SignInPasswordDeantextBox.Text.Trim().Equals(""))
                {
                    MessageBox.Show("Enter your password", "Password field is empty", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    MessageBox.Show("Wrong login or password", "Invalid data", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
Beispiel #3
0
        private void OkDeanButoon_Click(object sender, EventArgs e)
        {
            Connection     connection   = Connection.GetInstance();
            DataTable      dataTable    = new DataTable();
            SqlDataAdapter dataAdapter  = new SqlDataAdapter();
            SqlCommand     command      = new SqlCommand();
            SqlCommand     checkCommand = new SqlCommand();
            SqlDataReader  reader;
            bool           isDeanexist        = false;
            bool           isDeanFacultyExist = false;
            string         SqlQuery           = "select * from Dean where login = \'@log\' and password = \'@pass\';";
            string         pattern            = @"[a-zA-Z0-9]";
            string         sqlQuery1          = "select * from Dean";

            connection.OpenConnection();
            checkCommand.CommandText = sqlQuery1;
            checkCommand.Connection  = connection.GetConnection();
            reader = checkCommand.ExecuteReader();
            while (reader.Read())
            {
                if (LoginDeantextBox.Text == reader["login"].ToString())
                {
                    isDeanexist = true;
                    reader.Close();
                    break;
                }
            }
            reader.Close();
            reader = checkCommand.ExecuteReader();
            while (reader.Read())
            {
                if (UniversityDeantextBox.Text == reader["university"].ToString() && FacultyDeantextBox.Text == reader["faculty"].ToString())
                {
                    isDeanFacultyExist = true;
                    reader.Close();
                    break;
                }
            }

            command.CommandText = SqlQuery;
            command.Connection  = connection.GetConnection();
            if (Regex.IsMatch(LoginDeantextBox.Text, pattern, RegexOptions.IgnoreCase))
            {
                if (PasswordDeantextBox.Text.Length > 5)
                {
                    Hashing hashing = new Hashing(PasswordDeantextBox.Text);
                    command.Parameters.Add("@log", SqlDbType.VarChar).Value     = LoginDeantextBox.Text;
                    command.Parameters.Add("@pass", SqlDbType.VarChar).Value    = hashing.Hash;
                    command.Parameters.Add("@salt", SqlDbType.VarChar).Value    = hashing.Salt;
                    command.Parameters.Add("@univer", SqlDbType.VarChar).Value  = UniversityDeantextBox.Text;
                    command.Parameters.Add("@fac", SqlDbType.VarChar).Value     = FacultyDeantextBox.Text;
                    command.Parameters.Add("@name", SqlDbType.VarChar).Value    = NameDeantextBox.Text;
                    command.Parameters.Add("@surname", SqlDbType.VarChar).Value = SurnameDeantextBox.Text;
                    dataAdapter.SelectCommand = command;
                    dataAdapter.Fill(dataTable);
                    if (!isDeanexist)
                    {
                        if (!isDeanFacultyExist)
                        {
                            if (dataTable.Rows.Count == 0)
                            {
                                string sqlQuery2 = "insert into Dean(login,  name, surname, university, faculty, salt, password) values(@log, @name, @surname, @univer, @fac, @salt, @pass);";

                                command.Connection  = connection.GetConnection();
                                command.CommandText = sqlQuery2;
                                command.ExecuteNonQuery();
                                connection.CloseConnection();
                                MessageBox.Show("Your account was signed up", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                this.Hide();
                                DeanForm deanForm = new DeanForm();
                                deanForm.Show();
                            }
                        }
                        else
                        {
                            MessageBox.Show("This faculty already has a Dean!", "Used faculty", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Dean with this login is already exist!", "Used login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                else
                {
                    MessageBox.Show("Password must be longer than 5 symbols!", "Invalid password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Invalid login!", "Invalid login", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }