LinuxQuestions.org
Help answer threads with 0 replies.
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 09-29-2008, 07:41 PM   #1
sleepy0110
LQ Newbie
 
Registered: Sep 2008
Posts: 6

Rep: Reputation: 0
checking passwords against the linux /etc/passwd file


Hi,

I need to write a program that checks a password entered by a user against a password in the standard linux /etc/passwd file (I realize most linux distributions these days use shadow instead, but the system I'm dealing with still uses /etc/passwd)

I'm guess I would use the crypt function to encrypt the password given by the user. I do get confused on the salt input to the crypt function.
My understanding is that when a password is generated, the salt chosen to encrypt it is random. If that's the case, then I don't see how-to generate a comparable value from the user entered password to the password file.

Can anybody help me out on how I would check a pw entered by a user against the pw in the /etc/passwd file to see if it is correct?


Thanks.

Last edited by sleepy0110; 09-29-2008 at 07:42 PM.
 
Old 09-29-2008, 08:14 PM   #2
sleepy0110
LQ Newbie
 
Registered: Sep 2008
Posts: 6

Original Poster
Rep: Reputation: 0
Actually, figured it out. I was using the wrong salt value when doing the encryption.

In case others are wondering, the salt is found in the password file itself.

For MD5 based encryption (most modern) you'd have an encrypted pw that looks like this:
$1$wdU/3pY0$JRiqShV.12p6g8SabcT1fu
the salt value is: $1$wdU/3pY0$

so:
crypt("userEnteredPw", "$1$wdU/3pY0$");
Will give you: $1$wdU/3pY0$JRiqShV.12p6g8SabcT1fu

For DES, the password entry looks like this
A5di39f9k934d

the salt value is the first two characters: A5
so
crypt("userEnteredPW", "A5")
Will give you: A5di39f9k934d

All of the above is from the GNU C Library manual:
http://www.gnu.org/software/libc/man...ibc.html#crypt
 
Old 09-29-2008, 10:05 PM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,633
Blog Entries: 4

Rep: Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931
The trick is, though ... "that's not how you check passwords."

Most of the time, the system uses "shadow passwords" so that the /etc/passwd file does not contain any password information at all. The actual password information is stored in a place you can't get to.

Sometimes, computers use a centralized authentication mechanism like LDAP so that there are no stored passwords on any particular machine.

But... you can still check passwords. The mechanism for doing so is usually PAM: Pluggable Authentication Modules. This provides a standard way for programs to request authentication and receive "the answer, yes or no," while giving humans great flexibility in specifying how the authentication is actually to be determined.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Integrating MySQL and shadow passwd users/passwords wenberg Linux - Software 0 03-02-2005 04:02 PM
passwd fails when trying to change user passwords tamuct Linux - Security 4 12-07-2004 12:12 PM
Checking passwords and system clock in Python 1337 Twinkie Programming 9 10-31-2004 06:06 PM
Reading the passwd passwords BoldKiller Programming 2 05-21-2004 11:07 PM
xinetd startup script checking for writeable /etc/passwd ? markus1982 Linux - Security 11 10-16-2002 08:15 AM

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

All times are GMT -5. The time now is 02:22 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