on wo, 13 nov 2002 18:23:15 GMT, Christopher Burger wrote:
> Just a quick question. How can encrypt something with md5 encryption.
> I have passwords in a mysql database that are md5 encrypted. I was
> wondering if I can use something like
>
> $password = md5($input{'password'};
>
> to get the input encrypted and then check against the sql field for
> proper login.
You could use the md5_hex function from Digest::MD5, but there is another
way without the need for this module.
Suppose you have the following table definition:
CREATE TABLE users (
username CHAR(10) NOT NULL PRIMARY KEY,
password CHAR(32) NOT NULL
);
You can then insert new users with
my $sth_add_user = $dbh->prepare( qq{
INSERT INTO users
VALUES (?, md5(?))')
});
$sth_add_user->execute('Chris', 'Burger');
And you can check whether ($user, $pass) is a valid combination with
my $sql_check_password = qq{
SELECT
username
FROM user
WHERE
username = ?
AND md5(?) = password
};
my ($username) = $dbh->selectrow_array($sql_check_password, undef,
$user, $pass);
if (defined $username) {
# OK
} else {
# Not OK
}
--
felix
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]