Login Permissions

0

I'm doing a C # application where I've created a database for the login system where I have created users. In this login system I wanted to add permissions to certain users. For example, the program detects that it is the admin to log in and enables a certain button, while another user is disabled.

Is this possible? And how?

    
asked by anonymous 08.03.2018 / 13:21

1 answer

0

You can create a field in the table to know the type of user and / or hierarchy to know 'how will' validate who will have rights to the components of each module.

The example below is just a base since I do not know how your table is mounted. But initially this is how you can start thinking about your doubt.

private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                Usuario objUsuario = new Usuario();
                if (objUsuario.ConsultarUsuario(txtLogin.Text, txtSenha.Text) > 0)
                {
                    if (objUsuario.ChecarAcessoUsuario("opcCaixa", "", Metodos.codUsuario, Metodos.codGrupo))
                    {                        
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Usuário não possui acesso ao caixa loja!", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Login ou senha inválidos!","Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }







public bool ChecarAcessoUsuario(string menu, string acao, int usuario, string grupo)
        {
            try
            {
                var segnivel = ConsultarSegnivel1(menu);
                if (!string.IsNullOrEmpty(segnivel) && ConsultarDireitos(segnivel, usuario, grupo))
                {
                    return true;
                }
                segnivel = ConsultarSegnivel2(menu);
                if (!string.IsNullOrEmpty(segnivel) && ConsultarDireitos(segnivel, usuario, grupo))
                {
                    return true;
                }
                return false;
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    
08.03.2018 / 13:33