Changeset 278


Ignore:
Timestamp:
03/18/12 21:06:47 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Checkpoint, diversion to get userdata somewhere handy(er) for logging
Copy-paste base login processing from dns.cg to login() in DNSDB.pm.
See #35.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r277 r278  
    3535@ISA            = qw(Exporter);
    3636@EXPORT_OK      = qw(
    37         &initGlobals
     37        &initGlobals &login
    3838        &initPermissions &getPermissions &changePermissions &comparePermissions
    3939        &changeGroup
     
    5757@EXPORT         = (); # Export nothing by default.
    5858%EXPORT_TAGS    = ( ALL => [qw(
    59                 &initGlobals
     59                &initGlobals &login
    6060                &initPermissions &getPermissions &changePermissions &comparePermissions
    6161                &changeGroup
     
    145145
    146146## (Semi)private variables
     147
    147148# Hash of functions for validating record types.  Filled in initGlobals() since
    148149# it relies on visibility flags from the rectypes table in the DB
    149150my %validators;
     151
     152# Username, full name, ID - mainly for logging
     153my %userdata;
    150154
    151155
     
    929933  }
    930934} # end initGlobals
     935
     936
     937## DNSDB::login()
     938# Takes a database handle, username and password
     939# Returns a userdata hash (UID, GID, username, fullname parts) if username exists
     940# and password matches the one on file
     941# Returns undef otherwise
     942sub login {
     943  my $dbh = shift;
     944  my $user = shift;
     945  my $pass = shift;
     946
     947  %userdata = %{$dbh->selectrow_hashref("SELECT user_id,group_id,password,firstname,lastname FROM users WHERE username=?",
     948        undef, ($user) )};
     949  return if !%userdata;
     950
     951  if ($userdata{password} =~ m|^\$1\$([A-Za-z0-9/.]+)\$|) {
     952    # native passwords (crypt-md5)
     953    return if $userdata{password} ne unix_md5_crypt($pass,$1);
     954  } elsif ($userdata{password} =~ /^[0-9a-f]{32}$/) {
     955    # VegaDNS import (hex-coded MD5)
     956    return if $userdata{password} ne md5_hex($pass);
     957  } else {
     958    # plaintext (convenient now and then)
     959    return if $userdata{password} ne $pass;
     960  }
     961
     962  return %userdata;
     963} # end login()
    931964
    932965
Note: See TracChangeset for help on using the changeset viewer.