如何在 Perl CGI 程序中加密和解密密码?

发布于 2024-09-18 05:45:56 字数 255 浏览 7 评论 0原文

我是 Perl CGI 新手,使用 ActivePerl、SQLite DB、Apache 服务器和 Windows。 我有一个报名表,其中包含 ID、姓名、密码等字段 在。每当有人进行新输入时,无论他们输入什么密码 应加密并存储在数据库中的字段。

当同一用户下次输入密码时,应该对其进行验证。现在 我想需要解密函数或代码。

我发现了一种叫做 MD5 加密的东西。请任何人都可以给 向我提供有关此内容的更多信息,并帮助我了解如何编写代码或任何链接 关于这个?

Am new to Perl CGI, using ActivePerl, SQLite DB, Apache server and Windows.
I have an entry form in which their are fields like Id, Name, Password and so
on. Whenever anybody makes a new entry then whatever they enter into password
field that should be encrypted and get stored in database.

The next time when that same user enters the password then it should be validated. Now
I suppose a decrypt function or code is required.

I found something called MD5 encryption. Please can anybody give
me more info about this and help me regarding how to write the code or any link
regarding this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独享拥抱 2024-09-25 05:45:56

当你最初设置用户时调用make_crypto_hash,参数是他给定的密码。将函数返回值存储在数据库中。

sub make_crypto_hash {
    my ($passphrase) = @_;
    return Authen::Passphrase::BlowfishCrypt->new(
        cost        => 8,
        salt_random => 1,
        passphrase  => $passphrase,
    )->as_rfc2307;
}

当有人登录并且您想查看密码是否属于该用户时,调用 match_passphrase_against_crypto_hash。这些参数是您从数据库中检索给定用户名的加密哈希值以及用户刚刚给出的密码。返回值是布尔值。

sub match_passphrase_against_crypto_hash {
    my ($crypto_hash, $passphrase) = @_;
    return Authen::Passphrase::BlowfishCrypt
        ->from_rfc2307($crypto_hash)->match($passphrase);
}

Call make_crypto_hash when you initially set up the user, the parameter is his given passphrase. Store the function return value in the database.

sub make_crypto_hash {
    my ($passphrase) = @_;
    return Authen::Passphrase::BlowfishCrypt->new(
        cost        => 8,
        salt_random => 1,
        passphrase  => $passphrase,
    )->as_rfc2307;
}

Call match_passphrase_against_crypto_hash when someone logs in and you want to see whether the passphrase belongs to the user. The parameters are the crypto hash you retrieve from the database for the given user name, and the passphrase just given by the user. The return value is boolean.

sub match_passphrase_against_crypto_hash {
    my ($crypto_hash, $passphrase) = @_;
    return Authen::Passphrase::BlowfishCrypt
        ->from_rfc2307($crypto_hash)->match($passphrase);
}
负佳期 2024-09-25 05:45:56

MD5 将任何字符串转换为摘要。
要检查用户的密码是否有效,您不需要数据库中的密码,而只需将用户输入的摘要与您存储的摘要进行比较即可。

MD5 converts any string into a digest.
To check if the user's password is valid you don't need the password from the database, but only compare the digest from their entered one to the digest you stored.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文