protected void btnAcesso_Click(object sender, EventArgs e) { try { UsuarioDal ud = new UsuarioDal(); Usuario user = ud.Find(txtLogin.Text, Criptografia.EcriptarMD5(txtSenha.Text)); //Se usuario existe no banco, entra no IF if (user != null) { FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(user.Login, chkManterConectado.Checked, 5); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket)); Response.Cookies.Add(cookie); Response.Redirect("/Admin/ListagemClientes.aspx"); } else { lblMensagem.Text = "Usuario Não Encontrado."; } } catch (Exception ex) { lblMensagem.Text = ex.Message; } }
protected void btnCadastrar_Click(object sender, EventArgs e) { try { UsuarioDal ud = new UsuarioDal(); if ( ! ud.hasLogin(txtLogin.Text)) { Usuario user = new Usuario(); user.Nome = txtNome.Text; user.Email = txtEmail.Text; user.Login = txtLogin.Text; user.Senha = Criptografia.EcriptarMD5(txtSenha.Text); ud.Insert(user); lblMessagem.Text = "Usuario " + user.Nome + ", Cadastrado com Sucesso!"; txtNome.Text = string.Empty; txtEmail.Text = string.Empty; txtLogin.Text = string.Empty; txtNome.Focus(); } } catch (Exception ex) { throw new Exception("Erro: " + ex.Message); } }