kbradford has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a small password verification program for an NT Server. Whenever I use Win32:NetAdmin to return the password to the program, it is always null. Even when logged in as an admin or as the user. I've also tried LanMan and it does the same. Is there anyway to correct this? Thanks, Kevin.

Replies are listed 'Best First'.
Re: Using Win32::NetAdmin for passwords
by enoch (Chaplain) on Jun 16, 2001 at 00:59 UTC
    If you post the code you are using, I can probably help.
    On another note, why are you "returning" the password? Passwords are stored as hashes in the SAM, and I imagine, you are not looking for the hash. So, are you just looking for a succes or fail?

    update:
    But, just to do a little assuming, here is a code snippet. This uses Roth's Win32::AdminMisc module (and the code is obtained from the site).
    if( Win32::AdminMisc::UserCheckPassword("", $User, $Password)){ print "Password is correct.\n"; }else{ print "Password is not correct.\n"; }
    Jeremy
      Thanks for the tip, I didn't know about the AdminMisc module. Here's the code I have now using LanMan. The program retrieves the username and password from a transaction file, then checks three different account types for the password. Here's the verify sub:

      sub Verify {
      my ($server,$user) =@_;
      my %info;
      my %ainfo;
      my %onfo;
      $auser = "a" . "$empid";
      $ouser = "o" . "$empid";
      Win32::Lanman::NetUserGetInfo($server,$user,\%info);
      Win32::Lanman::NetUserGetInfo($server,$auser,\%ainfo);
      Win32::Lanman::NetUserGetInfo($server,$ouser,\%oinfo);
      if ($info{'password'} eq $ainfo{'password'}) {
      print "A account matches! $info{'password'} $ainfo{'password'}";
      }
      else {
      print "A account doesn't match!";
      }
      if ($info{'password'} eq $oinfo{'password'}) {
      print "O account matches!";
      }
      else {
      print "O account doesn't match!";
      }
      }

        Lanman does not seem to have a password key or value. Run this code:
        use Win32::LanMan qw(NetUserGetInfo); Win32::Lanman::NetUserGetInfo("","Administrator",\%info); foreach $key (keys %info) { print $key . " = " . $info{$key} . "\n"; }
        And you see that the output is:
        flags = 66049 logon_server = \\* last_logoff = 0 workstations = usr_comment = name = Administrator parms = auth_flags = 0 logon_hours =                       full_name = priv = 2 profile = password_age = 15750588 user_id = 500 units_per_week = 168 max_storage = -1 script_path = home_dir_drive = home_dir = country_code = 0 num_logons = 5 acct_expires = -1 primary_group_id = 513 last_logon = 984601420 password_expired = 0 code_page = 0 comment = Built-in account for administering the computer/domain bad_pw_count = 0
        There is no password field. So, you cannot compare them. I would use the AdminMisc module. It will probably work out better for you.

        Jeremy