|
Hi, for my use, i had implemented a simple mysql autentication function with relative configuration parameter in routers2.conf:
in [web] section of routers2.conf i put:
mysql-server = 127.0.0.1 mysql-database = authdb mysql-user = root mysql-pass = password
and i modify routers2.cgi in this way:
in user_verify function i add after readconf( 'web' );
if( defined( $config{'web-mysql-server'} ) ) { $rv = mysql_verify($u,$p); return $rv if($rv); }
and after sub ldap_verify i create the new function:
sub mysql_verify($$) { my($u, $p) = @_; require DBI;
my $dsn = "DBI:mysql:database=".$config{'web-mysql-database'}.";host=".$config{'web-mysql-server'}.";mysql_socket=/var/lib/m ysql/mysql.sock"; my $dbh = DBI->connect("$dsn", $config{'web-mysql-user'}, $config{'web-mysql-pass'}) or die "Couldn't connect to database: " . DBI->errstr; my $sthini = $dbh->prepare("SELECT PASSWORD(?),pass FROM users WHERE user=?") or die "Couldn't prepare statement: " . $dbh->errstr; $sthini->execute($p,$u) or die "Couldn't execute statement:" . $dbh->errstr; my @row = $sthini->fetchrow_array; $sthini->finish; if ($row[0] eq $row[1]) { return 1; } return 0; }
in mysql i create db authdb with this table structure:
CREATE TABLE `users` ( `user` varchar(15) NOT NULL, `pass` varchar(50) NOT NULL, PRIMARY KEY (`user`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
For add a user just a simple:
INSERT INTO `authdb`.`users` (`user` ,`pass`) VALUES ('username', PASSWORD( 'something' ));
And it works well for my needs. If you want to put this in future version i think is not so bad (it's a very simple mod). Also i think that if it's possible, it's a good idea to put in table structure also personalized configuration option that i must now put in routers2.conf [user-something] section. Bye. Marco Chiavacci
|