Changeset 55 for trunk/DNSDB.pm


Ignore:
Timestamp:
12/31/09 17:55:43 (14 years ago)
Author:
Kris Deugau
Message:

/trunk

Started adding logging calls
Fixed user add sub in DNSDB.pm so that it writes encrypted passwords
Added sub to check user credentials rather than keeping that process in the main program

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r51 r55  
    6767our %reverse_typemap;
    6868
     69
    6970##
    7071## Initialization and cleanup subs
    7172##
     73
    7274
    7375## DNSDB::connectDB()
     
    154156  }
    155157} # end initGlobals
     158
     159
     160## DNSDB::_log()
     161# Log an action
     162# Internal sub
     163# Takes a database handle, <foo>, <bar>
     164sub _log {
     165} # end _log
    156166
    157167
     
    489499    my $sth = $dbh->prepare("INSERT INTO users (group_id,username,password,firstname,lastname,phone,type,status) ".
    490500        "VALUES (?,?,?,?,?,?,?,?)");
    491     $sth->execute($group,$username,$pass,$fname,$lname,$phone,$type,$state);
     501    $sth->execute($group,$username,unix_md5_crypt($pass),$fname,$lname,$phone,$type,$state);
    492502
    493503    # get the ID...
     
    510520  }
    511521} # end addUser
     522
     523
     524## DNSDB::checkUser()
     525# Check user/pass combo on login
     526sub checkUser {
     527  my $dbh = shift;
     528  my $user = shift;
     529  my $pass = shift;
     530
     531  my $sth = $dbh->prepare("SELECT user_id,group_id,password,firstname,lastname FROM users WHERE username=?");
     532  $sth->execute($user);
     533  my ($uid,$gid,$pass,$fname,$lname) = $sth->fetchrow_array;
     534  my $loginfailed = 1 if !defined($uid);
     535
     536  if ($pass =~ m|^\$1\$([A-Za-z0-9/.]+)\$|) {
     537    $loginfailed = 1 if $pass ne unix_md5_crypt($pass,$1);
     538  } else {
     539    $loginfailed = 1 if $pass ne $pass;
     540  }
     541
     542  # nnnngggg
     543  return ($uid, $gid);
     544} # end checkUser
    512545
    513546
Note: See TracChangeset for help on using the changeset viewer.