[NTLUG:Discuss] authentication in a script

Jack Snodgrass jack at jacksnodgrass.com
Thu Apr 15 12:09:42 CDT 2004


On Thu, 2004-04-15 at 11:46, fredjame wrote:

> Is it possible to use some existing system call (like login) to 
> authenticate a user within a script (bash)?


With linux, almost anything is possible.... maybe hard.... but possible.

first of all... what/why are you doing this exactly? if you want to run
a command
on a remote system and handle the userid/password stuff automatically,
use 
ssh with keys that don't use passwords. Once you have the keys
generated, you can 
do something like
ssh remoteuser at remotesystem "ps -aef" 
and it will login without a password ( if you used a null password in
your key ) 
and execute the ps -aef command. You can run almost any remote command, 
pipe/grep the output and then run additional commands. 

if you don't want to use this method and do need to validate the
userid/password
that a user gives you......

I don't do this from bash... ( but I could....)  I have a php script (
you could
do it in perl but perl gives me a headache )  that takes the users
userid and password and it logs them into the IMAP server. (Since a
login 
doesn't access any mail... it's relatively cheap performance wise. )  If
they
get a succesful login, they are authenticated ( and I store a cookie so 
I only do this once a week per user ).... if the login fails, then they
are 
rejected. 

This is a php snippet of the code:
     $mbox = @imap_open ("{server:143}", $UserName, $Password);
     if($mbox == false) {
        print "Access denied. Invalid userid/password\n";
        return 0;
     } else {
        $rc = imap_close($mbox);
     }

    // if they get here, they are valid and I set the cookie. 

The question is... how do you want to store / get the userid / password.

jack



More information about the Discuss mailing list