I was able to use the passwdMD5 module with your example. I added a random 8 character salt. Everything works nicely. Thanks for the help. Is this the best standard to use right now in regards to perl and encryption?
Main Topics
Browse All TopicsI am using CGI::Session to pass variables from page to page (DBI as the data source for session data). I want to use MD5 or other encryption to encrypt password.
I have a user table and a session table.
1. What is the best way to encrypt the password when a user creates an account?
user submits a form with a password field.
assuming I have checked for password rules(length,complexity,et
looking for the best way to insert the password into user table but encrypted
2. What is the best way to check that the password?
user submits a login form with a password field
looking for the best way to check the plain text password against the encrypted password in the database
3. Should I...
a. store the encrypted password in the session and check against user table
b. store the plain text password in the session and check against user table using the same method as login (#2)?
Here is some of my session code...
#!/usr/bin/perl
##########################
use DBI;
use CGI::Session;
use CGI;
my $db_name="";
my $db_host="";
my $db_user="";
my $db_pass="";
$dbh = DBI->connect("DBI:mysql:da
"$db_pass", {PrintError => 1, RaiseError => 1, AutoCommit => 1});
my $cgi = new CGI;
my $sid = $cgi->cookie('CGISESSID') || $cgi->param('CGISESSID') || undef;
my $session = new CGI::Session("driver:MySQL
if ( $session->is_expired ) {
#Your session is expired. Please Login
#&expired;
}
if (!$sid) {
#No Session Exists. Please Login
#&no_session;
}
#Active Session;
if ($session_user && $session_pass) {
#Username and Password are present
#&check_user
#if pass... continue OK session exists and username and password match
#if fail... incorrect. Please Login
}
elsif (!$session_user || !$session_pass) {
#Account Error. Username or Password not present. Please Login
}
$session->expire(1800);
$cookie = $cgi->cookie(CGISESSID => $session->id );
print $cgi->header(-cookie=>$coo
$dbh->disconnect();
exit;
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
If you do a search on cpan for crypt, you'll find several options. I can't say which is best because I haven't tried most of them, I can only recommend the ones that I've used. I use Crypt::PasswdMD5 because it make it easy to authenticate against the unix shadow password, but there are also other methods that are just as easy.
If you don't include your own salt, the module will produce its own random 8 character salt.
Business Accounts
Answer for Membership
by: FishMongerPosted on 2006-08-30 at 09:59:00ID: 17421978
1. There are several methods to encrypt the password. I use the unix_md5_crypt fuction from the Crypt::PasswdMD5 module. ismunoz/Cr ypt-Passwd MD5-1.3/ Pa sswdMD5.pm
); ', 1);
sodb:$isos rv", $isouser, $isopass, ;
http://search.cpan.org/~lu
2. Encrypt the plain text password and then compare it to the user's encrypted password that is stored in a database.
3. Do not store either the plain or encrypted password in the session. Just do the comparison and if they don't match, redirect back to the login page or an error page. Here are 2 subroutines that I use in one of my login scripts that might help you.
sub authenticate_user {
if ( defined $login{'username'} && defined $login{'password'} ) {
my ($encrypted_pass, $roll, $name) = queryDB($login{'username'}
if ( $encrypted_pass ) {
my $salt = substr($encrypted_pass, 3,8);
my $password = unix_md5_crypt( $login{'password'}, $salt );
if ( $password eq $encrypted_pass ) {
$session->param('logged_in
$session->param('admin', $name);
return (1, $roll, $name);
}
}
}
$login{'failed'} = 'Invalid username, or password...Please try again';
return 0;
}
sub queryDB {
my $user = shift;
my $dbh = DBI->connect("DBI:mysql:$i
{'RaiseError' => 1, 'PrintError' => 0 })
or die "Connection Failed: $isodb DB on $isosrv\n\t$DBI::errstr\n"
my $sth = $dbh->prepare("SELECT password, roll, name
FROM users
WHERE id = '$user' and status = 'active' limit 1")
or die "prepare statemnet failed: $DBI::errstr\n";
$sth->execute;
my ($password, $roll, $name) = $sth->fetchrow_array;
$sth->finish;
$dbh->disconnect;
return ($password, $roll, $name);
}