LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-11-2006, 12:16 AM   #1
movitto
Member
 
Registered: May 2004
Distribution: Fedora 4 and Slackware
Posts: 179

Rep: Reputation: 30
Passwd Command and Algorithm


Hi. Is there anyway to run the passwd command or the same algorithm that it uses and not have it write the encrypted password to the /etc/shadow file, but rather the standard output? I ask because I am want to run an application with its own independent set of users/passwords, but with the same encryption scheme that linux uses. Thanks alot.
 
Old 04-11-2006, 01:21 AM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
I borrowed the following from a CVS howto years ago. IIRC it does the same thing as the passwd command. There's some info on it at http://cvsbook.red-bean.com/cvsbook.html:
Code:
#!/usr/bin/perl -w
#
# Used to generate the cvs passwd file
#

srand (time());
my $randletter = "(int (rand (26)) + (int (rand (1) + .5) % 2 ? 65 : 97))";
my $salt = sprintf ("%c%c", eval $randletter, eval $randletter);
my $plaintext = shift;
my $crypttext = crypt ($plaintext, $salt);

print "${crypttext}\n";
 
Old 04-11-2006, 10:12 AM   #3
operator10001
Member
 
Registered: Mar 2006
Distribution: debian sarge
Posts: 222

Rep: Reputation: 30
why not use xor?
 
Old 04-11-2006, 03:44 PM   #4
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
That script will generate encrypted passwords in the old /etc/passwd style. If you want to generate them in the /etc/shadow style, change the salt line to this:
Code:
my $salt = sprintf ("\$1\$%c%c%c%c\$", eval $randletter, eval $randletter, eval $randletter, eval $randletter);
You can have up to 8 '%c's, but each one must have a matching 'eval $randletter'.
 
Old 04-11-2006, 09:50 PM   #5
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
Thanks for that, CroMagnon
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Can't connect to DB when passing passwd on command line dimsh Linux - Software 2 11-08-2005 02:38 AM
The passwd command is usually set suid root. this is because, Simon Adebisi Linux - Software 1 06-28-2005 08:10 AM
passwd command is set in suid root. why??? Simon Adebisi Linux - Software 2 06-27-2005 10:02 PM
passwd command not working donovana Linux - General 3 03-09-2005 01:45 PM
Unexpected Behavior (passwd command) Penguin666 Linux - General 3 11-19-2003 11:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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