deadlyp99 Posted May 14, 2010 Share Posted May 14, 2010 Hey everyone at php freaks I have not touched programming a while and recently did, with intent on tackling perl, as well as playing around with AI type applications... perhaps more threads to come on that note! Picking up perl, I'd always associated it with python (which I decided the syntax is rubbish) but after actually trying it I am really liking how things are done for the most part. Anyway, I'm at a point where I want my application to have certain functions only accessible by me, its one and only master . Typically I like to create a DES cipher of my username and password, then use the key as a salt for an md5 hash to be stored in a database. Md5 looks a lot more pleasant when you look at your database, and at less risk of escaping code and whatnot, just my oppinion. The problem I am having is that, well for some reason Crypt:DES requires input, and keys to be exactly 8 bits. This is fine for now as I am not using any username:passwords longer than this. They are actually shorter, though I do imagine switching over to (using) CBC. So I need to be able to tag on a "\0" null to the variable, and I planned to have the program add or substring a string depending. When it hits the CheckLength function for checking that the variable is 8 bits, it runs for a bit then dies with a "Out of Memory!" error. I've got 3 gigs, and by reading I found that hashing is a bit wonky in perl. However I'm pretty convinced this is an error in method on my behalf and choose to not blame perl. Any help, hints, and tips would be appreciated, have a great day everyone AuthenticateUser.pm package Functions::AuthenticateUser; use Functions::Database; use Functions::HandleException; use Crypt::DES; use Digest::MD5 qw(md5_hex); $fHExc = Functions::HandleException; $fDbCon = Functions::Database; sub UserLogin; sub CheckLength; sub UserLogin { print "\n\nIn order to continue you need authenticate yourself!\nUsername: "; my $user = <>; Functions::AuthenticateUser -> CheckLength($user); print "\nPassword: "; my $pass = <>; $pass = CheckLength($pass); my $key = pack("H16", "2568647ff7468652"); my $cipher = new Crypt::DES $key; my $user = $cipher->encrypt($user); my $pass = $cipher->encrypt($pass); my $today = time(); $user = md5_hex($user.$key); $pass = md5_hex($pass.$key); print 'Login:'.$user.':'.$pass;exit; $fDbCon -> DbConnect('Login:'.$user.':'.$pass); } sub CheckLength() { my($class, $var) = @_; my $varlength = length($var); if ($varlength < 9) { $var += "\0"; CheckLength($var); } elsif ($varlength > 9) { $var = substr($var, 0, ; } return $var; } 1; Quote Link to comment https://forums.phpfreaks.com/topic/201757-perl-on-windows-just-started-learning-perl/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.