473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Linux System Users Login/Password?

Hi,

Has anyone managed to code anything that will verify the username and
password of a user against the /etc/shadow file?

I need to authenticate users based on their local system accounts, but
unfortunately need to do this without recompiling PHP or Apache with custom
modules.

So far I've managed to pull all of the shadow password strings out and into
a database, but is there any way of 'matching' the encrypted strings if you
are given the plain text version, like with md5?

Thanks in advance,
Vince.
Jun 13 '06 #1
5 2769
Vincent Pirez wrote:
Hi,

Has anyone managed to code anything that will verify the username and
password of a user against the /etc/shadow file?

I need to authenticate users based on their local system accounts, but
unfortunately need to do this without recompiling PHP or Apache with custom
modules.

So far I've managed to pull all of the shadow password strings out and into
a database, but is there any way of 'matching' the encrypted strings if you
are given the plain text version, like with md5?

Thanks in advance,
Vince.

PHP has a function named 'crypt' that will encrypt strings in the same
way the password is encrypted into the password file. It takes a
password string and a salt string.

The encryption algorithm may vary but is typically either a two
character salt (CRYPT_STD_DES) or an MD5 salt (CRYPT_MD5). The MD5
encryptions are guaranteed to start with a '$' sign.

So, for example, let's say your shadow entry is:
web:$2$Hlpmlp9i$5VnapGyOuIzJFkPcrvE7a.:13007:0:999 99:7:::

This is a MD5 encrypted password.

if( crypt($password, $salt) == '$2$Hlpmlp9i$5VnapGyOuIzJFkPcrvE7a.')) {
// password is correct
}

Do you really want to pull all the shadow entries into a database? Why
not read the file directly and explode() the entries? It seems to me
that you will have synchronization issues the other way.

-david-

Jun 13 '06 #2

"David Haynes" <da***********@sympatico.ca> wrote in message
news:2h*******************@fe06.usenetserver.com.. .
PHP has a function named 'crypt' that will encrypt strings in the same way
the password is encrypted into the password file. It takes a password
string and a salt string.

The encryption algorithm may vary but is typically either a two character
salt (CRYPT_STD_DES) or an MD5 salt (CRYPT_MD5). The MD5 encryptions are
guaranteed to start with a '$' sign.

So, for example, let's say your shadow entry is:
web:$2$Hlpmlp9i$5VnapGyOuIzJFkPcrvE7a.:13007:0:999 99:7:::

This is a MD5 encrypted password.

if( crypt($password, $salt) == '$2$Hlpmlp9i$5VnapGyOuIzJFkPcrvE7a.')) {
// password is correct
}

Do you really want to pull all the shadow entries into a database? Why not
read the file directly and explode() the entries? It seems to me that you
will have synchronization issues the other way.

-david-


Hi David,

Thanks for the great response. But how do I determine the matching salt?

Thanks,
Vince.
Jun 13 '06 #3
Vincent Pirez wrote:
"David Haynes" <da***********@sympatico.ca> wrote in message
news:2h*******************@fe06.usenetserver.com.. .
PHP has a function named 'crypt' that will encrypt strings in the same way
the password is encrypted into the password file. It takes a password
string and a salt string.

The encryption algorithm may vary but is typically either a two character
salt (CRYPT_STD_DES) or an MD5 salt (CRYPT_MD5). The MD5 encryptions are
guaranteed to start with a '$' sign.

So, for example, let's say your shadow entry is:
web:$2$Hlpmlp9i$5VnapGyOuIzJFkPcrvE7a.:13007:0:999 99:7:::

This is a MD5 encrypted password.

if( crypt($password, $salt) == '$2$Hlpmlp9i$5VnapGyOuIzJFkPcrvE7a.')) {
// password is correct
}

Do you really want to pull all the shadow entries into a database? Why not
read the file directly and explode() the entries? It seems to me that you
will have synchronization issues the other way.

-david-


Hi David,

Thanks for the great response. But how do I determine the matching salt?

Thanks,
Vince.

The short answer is that the salt of the encrypted password in the
shadow file is used.

A sample program:
<?php
$shadow_pw = '$1$Hlpmlp9i$5VnapGyOuIzJFkPcrvE7a.';
$my_pw = array('foofoofoo', 'letmein');

foreach( $my_pw as $pw ) {
if( crypt($pw, $shadow_pw) == $shadow_pw ) {
echo "The password $pw is good\n");
} else {
echo "The password $pw is bad\n");
}
}
?>

-david-

Jun 13 '06 #4

"David Haynes" <da***********@sympatico.ca> wrote in message
news:gY******************@fe46.usenetserver.com...

The short answer is that the salt of the encrypted password in the shadow
file is used.

A sample program:
<?php
$shadow_pw = '$1$Hlpmlp9i$5VnapGyOuIzJFkPcrvE7a.';
$my_pw = array('foofoofoo', 'letmein');

foreach( $my_pw as $pw ) {
if( crypt($pw, $shadow_pw) == $shadow_pw ) {
echo "The password $pw is good\n");
} else {
echo "The password $pw is bad\n");
}
}
?>


David,

Ahhh i get it now, by crypt()'ing the password against the shadow password
it somehow verifies.....I'm curious how this works, but don't need an
explanation unless anyone's willing to offer one?

Fact of the matter is it works, and is verifying nicely - many thanks for
your help David :)

Vince.
Jun 13 '06 #5
Vincent Pirez wrote:
David,

Ahhh i get it now, by crypt()'ing the password against the shadow password
it somehow verifies.....I'm curious how this works, but don't need an
explanation unless anyone's willing to offer one?
The first 'n' characters of any encrypted password is the salt used to
create the password. By supplying an encrypted password as the salt, you
are essentially providing the salt.
Fact of the matter is it works, and is verifying nicely - many thanks for
your help David :)


Cool! Glad its working out for you.

-david-

Jun 13 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: TheDD | last post by:
Hello every body, i have to do a news system wich use php/mysql. i need 3 accounts: * a 'reader' who doesn't need to log in to read the news * a 'writer' who can write news in a pending news...
2
by: Geiregat Jonas | last post by:
I'm running a linux system I would like to create a login system based upon the users and passwd of my linux box how could I do this ?
11
by: Tony Baker | last post by:
In order for my company to go ahead and use .Net and C# (over java), I need to know how to install and run a C# ASP.Net application not only on Windows, but on Linux. I'm a Windows developer,...
10
by: Fabrizio | last post by:
(Sorry for the crosspost, but I really don't know which is the right newsgroup!) Hi all, I try to change the password to a user that as to change the password at first logon: try {
9
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
2
by: astolpho | last post by:
I am using a slightly outdated reference book on J2EE programming. It gives 2 methods of creating a database used in its casestudies. The first is an ANT script that gives the following output: ...
6
by: SRK | last post by:
Hi, I have installed free TDS ODBC driver on Linux and from there I am trying to connect to MS SQLSERVER installed on Windows machine. But it gives me following error - tsql -H ps6312 -p 1433...
1
by: prasadshete | last post by:
Dear all, my system is $ uname -a Linux DLidps01 2.4.21-4.ELsmp #1 SMP Fri Oct 3 17:52:56 EDT 2003 i686 i686 i386 GNU/Linux 1.Now, i my a/c has sudo to root access. i do $sudo bash and enter...
13
by: Apostle | last post by:
Hi all, after thinking for sometimes, I thought it will be great opportunity to learn if I will start from scratch and build my own register/login system. Here is the thread that I will be posting...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.