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 05-19-2005, 11:23 PM   #1
MikeFoo1
Member
 
Registered: Apr 2004
Distribution: Slackware 9.1
Posts: 72

Rep: Reputation: 15
Generating hash in perl ?


Hi ,

How do i generate password hashes in perl (the ones stored in /etc/passwd)?I tried crypt/md5 but they don't match my /etc/passwd ones .
 
Old 05-21-2005, 01:57 AM   #2
freakyg
Member
 
Registered: Apr 2005
Distribution: LFS 5.0 and 6.1
Posts: 705

Rep: Reputation: 30
Re: Generating hash in perl ?

Quote:
Originally posted by MikeFoo1
Hi ,
tried crypt/md5 but they don't match my /etc/passwd ones .
of course........the shadow program generates the hash independent of outside
influence..........perl can be set to set/use an md5 hash, but they won't be the same..............
 
Old 05-21-2005, 05:57 AM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,795

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Try this code as root :
Code:
#!/usr/bin/perl

die "This script must be run as root\n"
    if not $< eq 0;

print "Enter a user UID: ";
chop($uid = <STDIN>);
$pwd = (getpwuid($uid))[1];

die "Can't get password for UID $uid\n"
    if not $pwd;

system "stty -echo";
print "Enter the password for this user: ";
chop($word = <STDIN>);
print "\n";

system "stty echo";

if (crypt($word, $pwd) ne $pwd) {
    die "Sorry, the password is wrong...\n";
} else {
    print "Ok, the password is correct\n";
}
To access shadow passwords, you have to be root

Last edited by keefaz; 05-21-2005 at 05:59 AM.
 
Old 05-21-2005, 07:03 PM   #4
MikeFoo1
Member
 
Registered: Apr 2004
Distribution: Slackware 9.1
Posts: 72

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by keefaz
Try this code as root :
Code:
#!/usr/bin/perl

die "This script must be run as root\n"
    if not $< eq 0;

print "Enter a user UID: ";
chop($uid = <STDIN>);
$pwd = (getpwuid($uid))[1];

die "Can't get password for UID $uid\n"
    if not $pwd;

system "stty -echo";
print "Enter the password for this user: ";
chop($word = <STDIN>);
print "\n";

system "stty echo";

if (crypt($word, $pwd) ne $pwd) {
    die "Sorry, the password is wrong...\n";
} else {
    print "Ok, the password is correct\n";
}
To access shadow passwords, you have to be root
Thanks . That works. I have a couple more questions but i will try something first :-) .
 
  


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
Perl and Hash automatic PB0711 Programming 3 09-23-2005 03:14 AM
Perl: hash tying amnesty_puppy Programming 1 01-18-2005 12:03 AM
Hash-sort like in PERL in C++ nyk Programming 4 06-11-2004 09:40 AM
Perl XML::Simple - Hash Question smaida Programming 2 05-26-2004 05:20 AM
renaming ENV hash in Perl nbp Programming 4 11-01-2003 04:07 AM

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

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