LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 09-27-2015, 12:46 PM   #1
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,576

Rep: Reputation: 179Reputation: 179
In C, given userID and password, can I verify the user?


I have a C program used for authentication with an email server. The server passes the C program the username and password. Is there a function I can call, e.g. verify_user(username, password)?
 
Old 09-27-2015, 01:18 PM   #2
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,576

Original Poster
Rep: Reputation: 179Reputation: 179
More info: I've come across this link http://www.tldp.org/HOWTO/Shadow-Password-HOWTO-8.html which may or may not be what I am looking for. But, I do not have libshadow.a on my system, nor referenced headers like shadow/pwauth.h, but I do have shadow.h

I'm using Slackware64 14.1. The system says package shadow-4.1.5.1-x86_64-3_slack14.1 is installed.

Need help!
 
Old 09-28-2015, 12:52 PM   #3
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,576

Original Poster
Rep: Reputation: 179Reputation: 179
I figured it out. The following example assumes argv[1] is the username and argv[2] is the plain-text password to authenticate. Note that access to /etc/shadow can only be done as root. Compile the program below with:

$ gcc testauth.c -o testauth -lcrypt

Code:
/*
 * Print information from the password entry
 * about the user name given as argv[1].
 */

int main( int argc, char** argv )
{
    char        *epasswd;

    struct spwd* sp;

        if (argc < 2) {
                printf("s username \n", argv[0]);
                return(EXIT_FAILURE);
        }

    if( ( sp = getspnam( argv[1] ) ) == (struct spwd*)0) {
      fprintf( stderr, "getspnam: unknown s\n",
        argv[1] );
      return( EXIT_FAILURE );
    }
    printf( "login name\t%s\n", sp->sp_namp );
    printf( "password\t%s\n", sp->sp_pwdp );

epasswd = crypt(argv[2], sp->sp_pwdp);
printf("crypt:\t\t%s, %d\n", epasswd, strcmp(epasswd, sp->sp_pwdp));
    return( EXIT_SUCCESS );
}
 
  


Reply

Tags
password, verify



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Verify which desktop ip logs into a common linux userid Cerephim Linux - Enterprise 1 09-23-2009 12:34 PM
UserID/Password to SMTP server (Thunderbird) billlee Linux - Networking 1 07-30-2005 05:59 PM
URGENT: Need to verify user's password in Linux proghrammatically vigosh_j Programming 5 01-26-2005 06:56 AM
command line to set a password to a new userid myhato Linux - Security 3 08-19-2004 11:46 PM
Central Userid and Password management in Linux sx10 Linux - Networking 3 09-06-2003 03:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 06:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration