Пример #1
0
        private void Login_Click(object sender, EventArgs e)
        {
            GlobalClass.userTableMapper selectedUser = ((GlobalClass.userTableMapper)LoginSelector.SelectedItem);
            string userHash = selectedUser.MD5HashPass;
            string userPass = passwdInput.Text;

            if (GlobalClass.VerifyMd5Hash(userPass, userHash))
            {
                GlobalClass.userRoleMapper SelectedRole = elementBase.roleSelectedUser(selectedUser.ID);
                if (SelectedRole.Admin)
                {
                    Admin admin = new Admin();
                    admin.setUser(selectedUser);
                    admin.Show();
                    this.Close();
                }
                else if (SelectedRole.AllowWrite)
                {
                    Teacher teacher = new Teacher();
                    teacher.Show();
                    this.Close();
                }
                else if (SelectedRole.AllowRead)
                {
                    Student student = new Student();
                    student.Show();
                    this.Close();
                }
            }
            else
            {
                this.LoginError.Text      = "Неверный пароль. Попробуйте ввести пароль заново или выберите другого пользователя";
                this.LoginError.ForeColor = Color.Red;
            }
        }
Пример #2
0
        public GlobalClass.userRoleMapper roleSelectedUser(int ID)
        {
            string query = "select * from userrole where ID = " + ID + " limit 1";

            GlobalClass.userRoleMapper userRole = new GlobalClass.userRoleMapper(ID, false, false, false);
            if (this.openConnection() == true)
            {
                MySqlCommand    cmd        = new MySqlCommand(query, dbConnect);
                MySqlDataReader dataReader = cmd.ExecuteReader();

                //Read the data and store them in the list
                while (dataReader.Read())
                {
                    int     I = (int)((long)dataReader["ID"]);
                    Boolean R = Convert.ToBoolean((sbyte)dataReader["allowRead"]);
                    Boolean W = Convert.ToBoolean((sbyte)dataReader["allowWrite"]);
                    Boolean A = Convert.ToBoolean((sbyte)dataReader["Admin"]);
                    userRole.setRole(R, W, A);
                }
                dataReader.Close();
                this.CloseConnection();
                return(userRole);
            }
            else
            {
                return(userRole);
            }
        }