Skip to content

Instantly share code, notes, and snippets.

@tacitochaves
Last active August 29, 2015 13:58
Show Gist options
  • Save tacitochaves/10173644 to your computer and use it in GitHub Desktop.
Save tacitochaves/10173644 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
my $cgi = new CGI;
my $usuario = $cgi->param("usuario");
my $password = $cgi->param("password");
# Filtrando dados
if ($usuario !~ /^[a-zA-Z]+$/ or $password !~ /^[a-zA-Z\d]+$/) {
print $cgi->header("text/html");
print "<h3 style='color: red;'> Os tipos de dados informados nao estao corretos</h3>";
} else {
my $root = "root";
my $pass = "123mudar";
my $host = "localhost";
my $db = "estudo_cgi";
my $mysql = DBI->connect("DBI:mysql:$db; host=$host", $root, $pass);
my $consulta = $mysql->prepare("SELECT * FROM login WHERE usuario='$usuario' AND password='$password'");
$consulta->execute();
my $encontrar = 0;
while ( $consulta->fetch() ) {
$encontrar = 1;
}
if ($encontrar eq 1) {
print $cgi->header("text/html");
print "<h3 style='color: blue;'> Bem vindo $usuario, os dados estao corretos</h3>";
} else {
print $cgi->header("text/html");
print "<h3 style='color: red;'> Os dados de acesso estao errados</h3>";
}
$mysql->disconnect();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment