in reply to Re^2: crypt help
in thread crypt help

Thats 8 bytes not bits !

If you want to use more than the first 8 bytes you will have to use another one way hash or cludge a crypto sub that splits your password into 8 byte chunks and crypts each seperately (Bad Idea). Perhaps MD5 hash would be nice, remember to add some salt to make dictionary attacks more expensive and if you store an MD5 you will have to store the salt as well (MD5 does not put it at the fromt like crypt does). Suppose you could use the MD5 of the user name as a salt, concatenate it with the password then store the MD5 of the result.

Here is your code fixed up a bit and altered to use md5 digest with MD5 of user name used as salt.

#!/usr/bin/perl use strict; use warnings; use Digest::MD5 ('md5_base64'); sub my_crypt { my ($pass, $user)=@_; my $salt = md5_base64($user); return md5_base64($salt.$pass); } print "user> "; chomp (my $user = <STDIN>); print "pass> "; chomp (my $pass = <STDIN>); my @salt = ('a'..'z', 'A'..'Z'); my $passc = my_crypt($pass, $user); open my $fh, '>>pass.pwd' or die $!; print $fh "$user\t$passc\n"; close($fh); # then i read it and check it like this: print "user> "; chomp ($user = <STDIN>); print "pass> "; chomp ($pass = <STDIN>); open $fh, '<pass.pwd' or die $!; my $matched; while(<$fh>){ next unless /^$user/; ($user, $passc) = split /\s+/, $_; if (my_crypt($pass, $user) eq $passc){ print "Matched\n"; $matched++; last; } } print "No Match\n" unless $matched; __END__ >./passtest user> random pass> test12345678 user> random pass> test12345678 Matched >rm pass.pwd >./passtest user> random pass> test12345678 user> random pass> test1234567 No Match >cat pass.pwd random 6EtC2Kp14XloIR7y4KdOQw

WARNING

Crypto is famous for subtle bugs. I give no promise that this algorithm is in any way secure but having said that I can see no obvious problems with it.

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

Replies are listed 'Best First'.
Re^4: crypt help
by dave_pl (Sexton) on Apr 05, 2005 at 10:06 UTC
    Random Walk
    Thank you for the help i will try the MD5 way you showd me
    my apologies for the 8bits and not 8bytes!
    THANKS AGAIN FOR THE WISDOM!!!!
Re^4: crypt help
by dave_pl (Sexton) on Apr 05, 2005 at 11:04 UTC
    Random_Walk
    Thank you for the help and showing the examples so clearly
    since i am still learning:) Sorry about the 8bit which
    should have been 8bytes!

    THANKS AGAIN FOR THE WISDOM!