如何在Perl CGI程序中加密和解密密码? [英] How can I encrypt and decrypt passwords in a Perl CGI program?

查看:140
本文介绍了如何在Perl CGI程序中加密和解密密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用ActivePerl,SQLite DB,Apache服务器和Windows是Perl CGI的新功能。
我有一个输入表单,其中包含ID,名称,密码等字段,因此
处于打开状态。每当有人输入新内容时,无论他们输入的密码
字段都应该被加密并存储在数据库中。

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.

我发现了一种称为MD5加密的东西。请有人可以给
我更多有关此的信息,并帮助我如何编写代码或与此有关的任何链接
吗?

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?

推荐答案

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

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;
}

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

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);
}

这篇关于如何在Perl CGI程序中加密和解密密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆