I need to write a script in Perl under Windows that will receive a username and a password. The script should authenticate the user against the user accounts in that machine, and also, it needs to check if the user belongs to the Administrators group. The server is not on any domain and doesn't have Active Directory, just local accounts.
I've been searching for a Perl solution but all I can find is about connecting to LDAP services. I also searched for ways to authenticate a user from command line but I couldn't find something that works for this case. Maybe I'm searching for the wrong words.
I'd like to know if any of you can think of a way to accomplish this.
Thanks in advance for any comments! :-)
Ok, so I found a way to accomplish this. I'd still like to hear from you guys to see if there's a better method.
Active State Perl includes a module called
Win32::UserAuthentication
, which is not documented (and is not on CPAN) and contains a warning about it not being maintained. However, it works over XS and returns a boolean when authenticating a local user. So far it works pretty well and fast for that part.For the checking of groups the user belongs to, I'm using this system command:
Which works pretty fast too and so far works for this purpose.
NOTE: For anyone trying the command above, I only have
grep
because it's on my system path thanks to havingCygwin
installed.If a better solution if proposed, I'll select it as best answer.
Thank you,
Francisco