示例#1
0
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        DataTable dt;
        string    Senha_Crip;

        dt = MySql.FillDataTable("SELECT LOGIN, SENHA FROM UsuariosAdmin WHERE LOGIN = '******'");
        if (dt.Rows.Count == 1)
        {
            Senha_Crip = FuncoesGerais.RetornaSHA512Base64(txtSenha.Text);
            if (Senha_Crip == dt.Rows[0]["SENHA"].ToString())
            {
                System.Web.Security.FormsAuthentication.RedirectFromLoginPage(txtUsuario.Text.ToUpper(), false);
            }
            else
            {
                lblErro.Visible = true;
                lblErro.Text    = "Senha incorreta.";
            }
        }
        else
        {
            lblErro.Visible = true;
            lblErro.Text    = "Login incorreto.";
        }
    }
    protected void btnOk_Click(object sender, EventArgs e)
    {
        try
        {
            string login     = txtLogin.Text.ToUpper().Trim();
            string nome      = txtNome.Text.ToUpper().Trim();
            string sobrenome = txtSobrenome.Text.ToUpper().Trim();
            string senha     = FuncoesGerais.RetornaSHA512Base64(txtSenha.Text.ToUpper().Trim());

            if (MySql.ExecuteNonQuery("INSERT INTO UsuariosAdmin ( login, nome, sobrenome, senha ) VALUES ('" + login + "','" + nome + "','" + sobrenome + "','" + senha + "') ") != 1)
            {
                throw new Exception("Erro ao inserir.");
            }
            lblMsg.Visible = false;
        }
        catch (Exception ex)
        {
            lblMsg.Visible = true;
            lblMsg.Text    = ex.Message;
        }
        finally
        {
            LimpaCampos();
        }
    }
示例#3
0
    protected void gvUsuarios_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        try
        {
            string      login     = gvUsuarios.DataKeys[e.RowIndex].Value.ToString();
            GridViewRow row       = gvUsuarios.Rows[e.RowIndex];
            string      nome      = ((TextBox)row.Cells[1].FindControl("txtNome")).Text;
            string      sobrenome = ((TextBox)row.Cells[1].FindControl("txtSobrenome")).Text;
            string      senha     = FuncoesGerais.RetornaSHA512Base64(((TextBox)row.Cells[3].FindControl("txtSenha")).Text);

            if (MySql.ExecuteNonQuery("UPDATE UsuariosAdmin SET NOME = '" + nome + "', SOBRENOME = '" + sobrenome + "', SENHA = '" + senha + "' WHERE LOGIN = '******' ") != 0)
            {
                gvUsuarios.EditIndex = -1;
                BindGrid();
                lblMsg.Visible = false;
            }
            else
            {
                throw new Exception("Erro ao atualizar.");
            }
        }
        catch (Exception ex)
        {
            lblMsg.Visible = true;
            lblMsg.Text    = ex.Message;
        }
    }