LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-18-2006, 07:39 AM   #1
abdel
LQ Newbie
 
Registered: Mar 2004
Location: Vellore
Distribution: Fedora core 5
Posts: 2

Rep: Reputation: 0
Validating a user using C


hello,
I am creating a program to validate a user (similar to what login command does) and need to validate wether a user and password is valid or not. As far as i searched i got functions to trverse the passwd file.. the functions are
setpwent(),getpwnam(), and endpwent().. but these functions do not compare the user entered password string with the passwd file string..
somebody pls tell me how to compare and what functions should i use to do it...
 
Old 07-19-2006, 01:05 AM   #2
ugenn
Member
 
Registered: Apr 2002
Posts: 549

Rep: Reputation: 30
Use the PAM library if you can.
 
Old 07-19-2006, 01:06 AM   #3
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Quote:
Originally Posted by abdel
hello,
I am creating a program to validate a user (similar to what login command does) and need to validate wether a user and password is valid or not. As far as i searched i got functions to trverse the passwd file.. the functions are
setpwent(),getpwnam(), and endpwent().. but these functions do not compare the user entered password string with the passwd file string..
somebody pls tell me how to compare and what functions should i use to do it...
Ok, first you read the user, then the password with getpass(), then you look up the encrypted password with getspnam(user) and you use sp_pwdp as the salt to call crypt(pass, sp->sp_pwdp). Then you compare the returned string to sp_pwdp. I hope I'm not missing anything.


PS: You may consider using the PAM framework. There are Howtos at www.tldp.org

Last edited by primo; 07-19-2006 at 01:10 AM.
 
  


Reply



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
Validating and Focussing In Java MRMadhav Programming 2 03-23-2006 09:02 PM
validating.... javier_ccs Programming 5 06-15-2005 08:22 AM
Validating user name/password kuna Programming 1 12-02-2004 10:39 PM
validating user input blanks Programming 3 09-02-2004 03:47 PM
validating a surname - regexp fu chr15t0 Programming 2 06-20-2003 05:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:29 AM.

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