Mudança de hábito: autenticando usuários em base de dados MySQL
O cadastro de novos usuários ocupa uma parte importante do tempo do administrador. Mas nem sempre é possível manter atualizada a lista de usuários cadastrados para acesso aos servidores da organização. O módulo pam_mysql permite autenticar usuários com o uso de uma base local centralizada, facilitando a gestão de pessoal.
Parte 2: Fixando as bases
Criaremos uma senha para o administrador do banco de dados e o próprio banco de autenticação. Complementaremos o procedimento com a criação de uma tabela para inclusão dos usuários temporários.
# mysqladmin -u root -p password 'm0d3rn0'
Enter password: *******
# mysql -u root -p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 47
Server version: 5.0.67-0ubuntu6 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> quit;
# mysqladmin create cadastro -p
Enter password: *******
# mysql -p
Enter password: *******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 47
Server version: 5.0.67-0ubuntu6 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> create table estagio (usuario varchar(30), email varchar(30),senha varchar(45), depart varchar (20));
mysql> show tables;
mysql> insert into estagio values('estagiario2','estagiario2@gmail.com',password('1234'),'contab');
mysql> insert into estagio values('estagiario3','estagiario3@bol.com.br',password('1234'),'juridico');
mysql> select * from estagio;
# mysqladmin -u root -p password 'm0d3rn0'
Enter password: *******
# mysql -u root -p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 47
Server version: 5.0.67-0ubuntu6 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> quit;
# mysqladmin create cadastro -p
Enter password: *******
# mysql -p
Enter password: *******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 47
Server version: 5.0.67-0ubuntu6 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------------+ | Database | +--------------------------+ | information_schema | | cadastro | | mysql | +--------------------------+ 3 rows in set (0.05 sec)mysql> use cadastro;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> create table estagio (usuario varchar(30), email varchar(30),senha varchar(45), depart varchar (20));
mysql> show tables;
+---------------------------+ | Tables_in_cadastro | +---------------------------+ | estagio | +---------------------------+ 1 row in set (0.00 sec)mysql> desc estagio;
+---------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | usuario | varchar(30) | YES | | NULL | | | email | varchar(30) | YES | | NULL | | | senha | varchar(45) | YES | | NULL | | | depart | varchar(20) | YES | | NULL | | +---------+--------------+------+-----+---------+-------+ 4 rows in set (0.00 sec)Podemos iniciar a inclusão de usuários:
mysql> insert into estagio values('estagiario2','estagiario2@gmail.com',password('1234'),'contab');
mysql> insert into estagio values('estagiario3','estagiario3@bol.com.br',password('1234'),'juridico');
mysql> select * from estagio;
+-------------+--------------------+----------------+----------+ | usuario | email | senha | depart | +-------------+--------------------+----------------+----------+ | estagiario2 | estagio2@gmail.com | *A4B61...0BFCF | contab | | estagiario3 | estagio3@bol.com.br| *A4B61...EBFCF | juridico | +-------------+--------------------+----------------+----------+ 2 rows in set (0.02 sec)Teremos os usuários habilitados para autenticar através do banco instalado.
Interessante ...
Artigo bem explicado naum me recordo de ver um artigo aqui na vol descrito dessa forma bem simples. Uma boa alternativa para o LDAP. Aguardando suas diferenças e funções.É claro !!!
Parabens.
Lucas Rocha