A1. Getting the Encrypted Password
[Previous] [Main] [Next]

A1 Getting the Encrypted Password


You need to paste the password into the CVSROOT/passwd file. You can get a copy from the GNU/Linux password file or the shadow file or run a PERL script.

Here is my favorite:
#!/usr/bin/perl
# From "The Linux Development Platform" by Rehman
# Simple script to take a user name and password and generate an
# encrypted password for the $CVSROOT/CVSROOT/passwd file.
# Standard usage ./cvspassgen USERNAME PASSWORD
# Alternate usage ./cvspassgen USERNAME PASSWORD >> passwd
# Note:  you must be in the $CVSROOT/CVSROOT folder or add a path after
#  the >>.  NOTE the double ">>".  If you use a single, you will wipe out
# the existing passwd file.
($u, $p)=@ARGV;
@d=(A..Z,a..z);
$s=$d[rand(52)].$d[rand(52)]; 
# use this line if everyone is using the rights from the cvs account.
print $u.":".crypt($s, $p).":cvs\n";
# use this line if everyone is using their own rights.
#print $u.":".crypt($s, $p)."\n";



Here is the PERL script from the CVS book (Note see below for another script that worked for me).
#!/usr/bin/perl

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";
He keeps the preceding script in /usr/local/bin/cryptout.pl:
floss$ ls -l /usr/local/bin/cryptout.pl

-rwxr-xr-x   1   root   root   265  Jun 14 20:41 /usr/local/bin/cryptout.pl
floss$ cryptout.pl "some text"
sB3A79YDX5L4s


That one actually did not work for me, so here is another one I found that did work.

#!/usr/bin/perl -w

# Perl based passwd generation file, original to Richard Caley.
#
# This program prints the unencrypted password on standard output
# followed by the encrypted password.
#

$saltchars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./';

while (<>) {
    chomp $_;

    my ($salt) = substr($saltchars, rand(64), 1) . substr($saltchars, rand(64), 1);
    my ($c) = crypt($_, $salt);
    print "'$_' => '$c'\n";
}