Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 11-10-2005, 12:04 PM   #1
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 670
Blog Entries: 7

Rep: Reputation: 31
php + MD5 ==> gone crazy..!!!

Hi guys Ive been working on this one for a couple of hours and I still havent figured it out........Ive got a script to add users it worked fine but the problem was that I needed to hash the password in the useradd -p argument to make the whole process valid.......when I hash the password nothing happens the script does not give me any output.....ex: if I try to add the same users twice the system would have presented me with the output of the useradd command "users exists" but now it just swallows my input without further notic

//create the user with the supplied args
$command = "sudo useradd $username ";
if($group != "")
$command = $command. "-g $group ";
$command = $command. "-d $home_dir ";
if($shell == "")
$command = $command. "-s /bin/bash ";
$command = $command. "-s shell ";
$command = $command. "-c $comment ";
//the line below is used to hash the password
$encrypted_pwd = "sudo openssl passwd -crypt $password";
//asign password to the output of the encrypt function
$password = shell_exec($encrypted_pwd);
$command = $command. "-p $password ";
$command = $command.' 2>&1';
$function_call = shell_exec($command);
echo $function_call
//The problem is that echo $function_call is not sending anything even if I try to send the same username more than once........that does not happen when I remove the hashed password and jsut supply a usertyped password......
Old 11-11-2005, 06:23 AM   #2
Registered: Oct 2005
Posts: 51

Rep: Reputation: 16
I am no expert, but I just saw this thread on that may be a result of the same problem you're having:
Apparently MySQL 4.1 handles passwords somewhat differently than 4.0.
Old 11-11-2005, 04:25 PM   #3
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 670
Blog Entries: 7

Original Poster
Rep: Reputation: 31
Ok for all those guys who might need an answer to this question .........use the crypt() function in PHP, it takes to arguments one is the word to be hashed and the second is the hash salt..........actually the second argument determines what kind of hashing you want ot use.......md5 standard des blowfish etc..........when you get the output give it to useradd -p $output and it will work just fine......


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
c++ md5 develinux Programming 2 02-28-2009 11:38 AM
Md5 hlinux Fedora 2 06-28-2005 11:21 PM
md5 RDove Programming 3 03-07-2005 11:22 AM
PHP md5 oddity gk_ Programming 0 01-10-2005 09:23 PM
using iso.md5 and iso.md5.asc Tyir Linux - Newbie 3 07-11-2004 12:45 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:25 AM.

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