LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-17-2007, 06:20 AM   #1
blunt
LQ Newbie
 
Registered: Oct 2006
Posts: 24

Rep: Reputation: 15
Howto compare password in /etc/shadow


Hello.

I'm trying to develop a PHP script to control some functions in my server. The server has VPS and I want to create a simple script which allows the root user of the VPS to reboot it, from a graphical interface instead of from shell access.

What I need is to compare the password the user enters in the PHP form, with the root passowrd from the /etc/shadow file he has in his VPS. Is there any method of converting a plain password to the shadow format so I can compare it to the one contained in the /etc/shadow file?

Is there any other (maybe more efective) way of doing this, without having to for example, create a table in mysql with users and passwords and check the login form against that information?

Thank you
 
Old 04-17-2007, 09:55 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
I can only help you from the C world; I don't know jack about PHP. But maybe this will give you a first step.

See these pages:

Code:
man 5 shadow
man 3 shadow
man 3 crypt
Hope this is of some help.
 
Old 04-17-2007, 10:14 AM   #3
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
If the root password hash from the shadow file is in $rootpw, and the input password is in $password, use this:
Code:
if($rootpw==crypt($password,$rootpw)){
    // correct password
} else {
    // incorrect password
}
 
Old 04-17-2007, 04:20 PM   #4
blunt
LQ Newbie
 
Registered: Oct 2006
Posts: 24

Original Poster
Rep: Reputation: 15
thank you wjevans for your reply. I had read some of the man pages, but not all of the three you mentioned. It doesn't help much about PHP, bue it does provide some necessary info.

Thank you Matir for your post, I had already found some info about the PHP needed to test the passwords, and although your solution provides correct result, it seems that the crypt function from PHP only needs the first 2 characters from the encrypted shadow password as salt to provide the correct encrypted pass.

Besides that, I figured out that I need suexec installed with apache and PHP in order to be able to read the /etc/shadow file.
It all seems to work now.

thank you both
 
Old 04-17-2007, 04:55 PM   #5
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
If you only need the first 2 characters you are probably using DES passwords... a tiny bit outdated, you may want to update.
 
Old 04-18-2007, 05:41 AM   #6
blunt
LQ Newbie
 
Registered: Oct 2006
Posts: 24

Original Poster
Rep: Reputation: 15
Yes, the VPSs have encrypted passwords that only use the 2 first characters. They run on Debian Sarge. I don't really know how to update that...

But now I'm having another problem...I can get the script to work if I type "php myscript.php" in the shell, bue if I go to the browser, I only get a 403 forbidden error...Any guess on why this is happening? Is my apache not working well with suexec?

Thank you
 
  


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
Howto compare two strings in C daYz Programming 20 03-04-2007 04:10 AM
Compare LDAP password with php crypt password coolamit78 Linux - Networking 1 01-30-2006 05:35 AM
shadow password - password field ayhopkins Linux - Security 8 11-17-2005 05:25 AM
useradd without shadow password twallstr Linux - Software 1 09-08-2005 02:14 PM
shadow password wincrk Linux - Security 3 03-16-2003 09:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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